package This;
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.JPasswordField;
import javax.swing.JTextField;
public class Main {
public static void main(String[]args){
LoginDemo LD=new LoginDemo();
}
}
class LoginDemo extends JFrame{
private String username="123";
private String passkey="123";
JFrame window;
//用户名,密码
JTextField user;
JTextField pwd;
//登录按钮
JButton Login;
public LoginDemo(){
window=new JFrame("学生管理系统");
window.setSize(600,600);
window.setLocationRelativeTo(null);
window.setLayout(null);
window.setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
window.setVisible(true);
JLabel name =new JLabel("用户名:");
name.setBounds(150,100,100,100);
window.add(name);
JLabel key =new JLabel("密码:");
key.setBounds(150,150,100,100);
window.add(key);
user=new JTextField ();
user.setBounds(200,130,300,40);
window.add(user);
String use=user.getText();
pwd=new JPasswordField();
pwd.setBounds(200,180,300,40);
window.add(pwd);
String pw=pwd.getText();
Login=new JButton("登录");
Login.setBounds(250,300,100,50);
window.add(Login);
//设置点击事件
Login.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if (use.equals(username)) {
if(pw.equals(passkey)) {
System.out.println("正确");
}
else {
System.out.println("错误");
}
}
else {
System.out.println("错误");
}
}
});
}
}