📄 logindemo.java
字号:
import java.awt.*;
import java.awt.event.*;
public class LoginDemo extends Frame implements ActionListener
{
Label lbl1;
Label lbl2;
Label lbl3;
TextField tf1;
TextField tf2;
Button bt1;
Button bt2;
LoginDemo()
{
super("Login Window");
lbl1=new Label("name");
lbl2=new Label("age");
lbl3=new Label(" ");
tf1=new TextField(20);
tf2=new TextField(20);
bt1=new Button("ok");
bt2=new Button("canel");
this.setLayout(new GridLayout(4,2));
this.add(lbl1);
this.add(tf1);
this.add(lbl2);
this.add(tf2);
this.add(bt1);
this.add(bt2);
this.add(lbl3);
bt1.addActionListener(this);
bt2.addActionListener(this);
this.setSize(200,300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
Object obj=e.getSource();
if(obj==bt1)
lbl3.setText("name:"+tf1.getText()+(char)13+(char)10+"age:"+tf2.getText());
else if(obj==bt2)
{
System.exit(0);
this.dispose();
}
}
public static void main(String args[])
{
new LoginDemo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -