ADD file via upload

main
nxist2202005056 1 year ago
parent b631906f9f
commit 914fc3a3cb

@ -0,0 +1,67 @@
package com.WR.StudentMS.view;
import javax.swing.*;
import com.WR.StudentMS.dao.mysql.TAdmindaoimplzh;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class LoginFrame extends JFrame {
private JTextField txtUserName;
private JPasswordField txtPassword;
public LoginFrame() {
setTitle("登录");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null); // 居中窗口
setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
txtUserName = new JTextField(20);
txtPassword = new JPasswordField(20);
JButton btnLogin = new JButton("登录");
JButton btnCancel = new JButton("取消");
btnLogin.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 登录逻辑
String userName = txtUserName.getText();
String userId = new String(txtPassword.getPassword()); // 密码是字符串
if (login(userName, userId)) {
JOptionPane.showMessageDialog(null, "登录成功!");
// 进入主界面
MainFarme mainFarme = new MainFarme();
mainFarme.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
}
}
});
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
add(new JLabel("用户名:"));
add(txtUserName);
add(new JLabel("用户ID密码"));
add(txtPassword);
add(btnLogin);
add(btnCancel);
pack();
}
private boolean login(String userName, String userPw) {
TAdmindaoimplzh adminDao = new TAdmindaoimplzh();
return adminDao.verifyCredentials(userName, userPw); // 使用 verifyCredentials 进行验证
}
}
Loading…
Cancel
Save