📄 guiexample1.java
字号:
import java.awt.event.*;
import java.awt.*;
public class guiexample1 extends Frame {
private Button b1=new Button("登录");
private Button b2=new Button("重置");
private Button db1=new Button("确定");
private Dialog d=new Dialog(this,"登录结果",false);
private Label l3=new Label();
TextField txt1,txt2;
public guiexample1(String ss)
{
super(ss);
d.setLayout(new FlowLayout());
d.add(l3);
d.add(db1);
db1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
d.dispose();}
} );
d.setSize(200,100);
setLayout(new FlowLayout());
Label l1=new Label("用户名:");
add(l1);
txt1=new TextField(5);
add(txt1);
Label l2=new Label("密码 :");
add(l2);
txt2=new TextField(8);
txt2.setEchoChar('*');
add(txt2);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
b1_actionPerformed(e);}
} );
add(b1);
b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
txt1.setText("");
txt2.setText("");}
} );
add(b2);}
protected void b1_actionPerformed(ActionEvent e){
String s1=txt1.getText();
String s2=txt2.getText();
if(s1.equals("admin") && s2.equals("123456"))
l3.setText("Welcome!");
else
l3.setText("Wrong");
d.show();
}
public static void main(String args[]) {
guiexample1 nowFrame=new guiexample1("用户登录 ");
nowFrame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
nowFrame.pack();
nowFrame.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -