package fuxi_bao;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Login extends JFrame implements ActionListener{
JPanel jp;
JLabel name;
JLabel password;
JLabel show;
JTextField jname;
JTextField jpassword;
JButton login;
JButton reset;
JButton register;
public Login(){
jp=new JPanel();
name=new JLabel("清输入用户名:");
password=new JLabel("清输入密码:");
show=new JLabel("");
login=new JButton("登陆");
reset=new JButton("重置");
register =new JButton("注册");
jname=new JTextField(15);
jpassword=new JTextField(16);
//jpassword.SetEchoChar('*');
jp.add(name);
jp.add(password);
jp.add(jname);
jp.add(jpassword);
jp.add(login);
jp.add(reset);
jp.add(register);
jp.add(show);
login.addActionListener(this);
reset.addActionListener(this);
register.addActionListener(this);
this.add(jp);
this.setTitle("登陆窗口");
this.setSize(500,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==reset)
{
show.setText("");
jname.setText("");
jpassword.setText("");
}
else if(e.getSource()==register){
show.setText("进入注册页面");
}
else{
if(jname.getText().equals("abc") && jpassword.getText().equals("1234")){
show.setText("登陆成功");
}
else{
show.setText("账号或者密码错误");
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new Login();
}
}
|
|