import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class T2 {
/**
* @param args
*/
private static JFrame frame;
private JTextField t1,t2;
private JPasswordField password;
private JLabel b1,b2,b3,b4;
private JButton btn1,btn2;
public T2(){
frame=new JFrame();
frame.setSize(300,400);
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
b1=new JLabel("用户名");
b2=new JLabel("密码");
t1=new JTextField(10);
password=new JPasswordField(10);
btn1=new JButton("登陆");
btn2=new JButton("取消");
frame.add(b1);
frame.add(t1);
frame.add(b2);
frame.add(password);
frame.add(btn1);
frame.add(btn2);
btn1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if((t1.getText().trim()).equals("余雪鹏") && (password.getText().trim()).equals("123456"))
{
b3=new JLabel("密码正确,登陆成功!");
frame.add(b3);
frame.setVisible(true);
}
else{
b4=new JLabel("密码错误 ,找回密码!");
frame.add(b4);
frame.setVisible(true);
}
}
});
btn2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(e.getSource()==btn2)
{
System.exit(0);
}
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new T2();
frame.setVisible(true);
}
}
java实现登陆界面
最新推荐文章于 2024-11-19 22:45:09 发布