Init student

This commit is contained in:
GGB
2022-06-10 01:32:14 +08:00
parent d41c67dd80
commit 08da72e735
12 changed files with 361 additions and 133 deletions

View File

@@ -1,47 +1,78 @@
package com.cfive.classroom.student;
import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.bean.Student;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException;
import com.formdev.flatlaf.FlatLightLaf;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.sql.SQLException;
public class MainWindow{
private static final MainWindow mainWindow = new MainWindow();
private JPanel rootPanel;
private JLabel title;
private JTextField textField1;
private JPasswordField passwordField1;
private JTextField stuNoText;
private JPasswordField passwordText;
private JButton login;
static JFrame frame = new JFrame("学生登录界面");
private JLabel password;
private static JFrame frame = new JFrame("学生登录界面");
private static final Logger LOGGER = LogManager.getLogger();
public MainWindow() {
//登录按钮
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(check()){
Center center = new Center();
center.start();
frame.setVisible(false);
center.start(String.valueOf(stuNoText.getText()));
frame.dispose();
}
}
});
}
public boolean check(){
String password = new String(passwordField1.getPassword());
if (textField1.getText() == null || password.length() == 0) {
String stuPassword = new String(passwordText.getPassword());
String stuNo = new String(stuNoText.getText());
LOGGER.info(Long.valueOf(stuNo));
//判断密码
if (stuNo.length() == 0 || stuPassword.length() == 0) {
JOptionPane.showMessageDialog(null, "账号密码不能为空");
return false;
} else {
return true;
boolean checkPassword=false;
try {
checkPassword=DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo),stuPassword);
} catch (NoConfigException e) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException",e);
} catch (DependenciesNotFoundException e) {
LOGGER.error("DependenciesNotFoundException",e);
} catch (NoSuchAlgorithmException e) {
LOGGER.error("NoSuchAlgorithmException",e);
} catch (InvalidKeySpecException e) {
LOGGER.error("InvalidKeySpecException",e);
}
return checkPassword;
}
}
public static void main(String[] args) {
frame.setContentPane(new MainWindow().rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// frame.pack();
frame.setBounds(650,300,600,400);
FlatLightLaf.setup();
frame.setContentPane(mainWindow.rootPanel);
frame.setSize(600,400);
frame.setTitle("登录");
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setResizable(false);
}