学生管理系统
public class LoginFrame extends JFrame {
private String username;
private String password;
private JLabel lblUsername;
private JLabel lblPassword;
private JTextField txtUsername;
private JPasswordField txtPassword;
private JButton btnOK;
private JButton btnCancel;
private JButton btnSign;
private JPanel panel, panel1, panel2, panel3, panel4;
public LoginFrame(String title) {
super(title);
initGUI();
eventsHandling();
}
private void eventsHandling() {
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
username = txtUsername.getText().trim();
password = new String(txtPassword.getPassword());
UserService userService = new UserService();
User user = userService.login(username, password);
if (user != null) {
try {
new Main();
JOptionPane.showMessageDialog(null, "恭喜【"+ username + "】登录成功~");
} catch (IOException ioException) {
System.err.println("失败~");
}
dispose();
} else {
JOptionPane.showMessageDialog(null, "【"+ username + "】登录失败~\n用户名或密码错误~");
txtUsername.setText("");
txtPassword.setText("");
txtUsername.requestFocus();
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e)