该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
package text1;
import java.awt.*;
import java.awt.event.*;
public class Example {
static TextField tf1, tf2;
static Label label;
public static void main(String[] args) {
Frame f = new Frame("我的窗口");
f.setLayout(null);
f.setSize(400,300);
f.setLocation(300,200);
f.setVisible(true);
MyWindowListerner mw= new MyWindowListerner();
f.addWindowListener(mw);
/*Label*/label =new Label();
f.add(label);
label.setBounds(40,200,150,30);
String s = "欢迎~";
label.setText(s);
/*TextField*/ tf1 = new TextField(30);
tf1.setBounds(40,60,150,30);
f.add(tf1);
/*TextField*/ tf2 = new TextField(30);
tf2.setBounds(40,100,150,30);
f.add(tf2);
Button button1 =new Button("确定");
f.add(button1);
button1.setBounds(40,150,50,30);
button1.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
String s1 = tf1.getText();
String s2 = tf2.getText();
if (s1 == "111" && s2 == "123")
label.setText("登录成功");
else
label.setText("登录失败");
}
});
Button button2 =new Button("取消");
f.add(button2);
button2.setBounds(100,150,50,30);
button2.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
System.exit(0);
}
});
f.setVisible(true);
}
}
class MyWindowListerner implements WindowListener{
public void windowClosing(WindowEvent e){
Window window = e.getWindow();
window.setVisible(false);
window.dispose();
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
}