📄 ch9_33.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ch9_33 extends JFrame
{
{
setBounds(20,20,500,300);
getContentPane().setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String [] args)
{
ch9_33 f=new ch9_33();
f.getContentPane().setLayout(new BorderLayout());
JPanel p1=new JPanel();
p1.setLayout(new GridBagLayout());
GridBagConstraints gbc=new GridBagConstraints();
gbc.anchor=GridBagConstraints.WEST;
gbc.insets=new Insets(2,2,2,2);
p1.setBorder(BorderFactory.createTitledBorder("你的基本数据"));
JLabel l1=new JLabel("姓名:");
JLabel l2=new JLabel("性别:");
JLabel l3=new JLabel("身高:");
JLabel l4=new JLabel("体重:");
JPasswordField t1=new JPasswordField();
JPasswordField t2=new JPasswordField(2);
JPasswordField t3=new JPasswordField("175cm");
JPasswordField t4=new JPasswordField("50kg-太瘦了",10);
// 默认的为*,利用下面的方法改变
t1.setEchoChar('#');
t2.setEchoChar('%');
t3.setEchoChar('&');
t4.setEchoChar('m');
gbc.gridy=1;
gbc.gridx=0;
p1.add(l1,gbc);
gbc.gridx=1;
p1.add(t1,gbc);
gbc.gridy=2;
gbc.gridx=0;
p1.add(l2,gbc);
gbc.gridx=1;
p1.add(t2,gbc);
gbc.gridy=3;
gbc.gridx=0;
p1.add(l3,gbc);
gbc.gridx=1;
p1.add(t3,gbc);
gbc.gridy=4;
gbc.gridx=0;
p1.add(l4,gbc);
gbc.gridx=1;
p1.add(t4,gbc);
f.getContentPane().add(p1);
f.pack();
f.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -