?? 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 + -