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

4
.idea/dataSources.xml generated
View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true"> <component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="@10.14.0.7" uuid="0c1ff8c3-597c-4b0b-8aed-28afff151eb1"> <data-source source="LOCAL" name="class@10.14.0.7" uuid="0c1ff8c3-597c-4b0b-8aed-28afff151eb1">
<driver-ref>mysql.8</driver-ref> <driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver> <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://10.14.0.7:3306</jdbc-url> <jdbc-url>jdbc:mysql://10.14.0.7:3306/class</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir> <working-dir>$ProjectFileDir$</working-dir>
</data-source> </data-source>
</component> </component>

View File

@@ -0,0 +1,2 @@
host=127.0.0.1
port=8888

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.cfive.classroom.student.Center"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.cfive.classroom.student.Center">
<grid id="27dc6" binding="rootpanel2" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="rootpanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="50" left="50" bottom="50" right="50"/> <margin top="50" left="50" bottom="50" right="50"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="500" height="400"/>
@@ -16,7 +16,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="1a8f9" class="javax.swing.JButton" binding="button2"> <component id="1a8f9" class="javax.swing.JButton" binding="raiseHandButton">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="80" height="40"/> <preferred-size width="80" height="40"/>
@@ -41,17 +41,10 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Microsoft YaHei" size="20" style="0"/>
<text value="学号"/> <text value="学号"/>
</properties> </properties>
</component> </component>
<component id="24679" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="58188" class="javax.swing.JButton" binding="changePasswordButton"> <component id="58188" class="javax.swing.JButton" binding="changePasswordButton">
<constraints> <constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
@@ -60,6 +53,16 @@
<text value="修改密码"/> <text value="修改密码"/>
</properties> </properties>
</component> </component>
<component id="2c923" class="javax.swing.JTextField" binding="stuNoText">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
</children> </children>
</grid> </grid>
<grid id="9734" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="9734" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
@@ -70,7 +73,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="47a94" class="javax.swing.JButton" binding="Button1"> <component id="47a94" class="javax.swing.JButton" binding="signInButton">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="80" height="40"/> <preferred-size width="80" height="40"/>
@@ -97,7 +100,7 @@
</grid> </grid>
</constraints> </constraints>
<properties> <properties>
<text value="聊天"/> <text value="留言"/>
</properties> </properties>
</component> </component>
</children> </children>
@@ -115,10 +118,11 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Microsoft YaHei" size="20" style="0"/>
<text value="课程"/> <text value="课程"/>
</properties> </properties>
</component> </component>
<component id="8648e" class="javax.swing.JTextArea" binding="textArea1" default-binding="true"> <component id="8648e" class="javax.swing.JTextArea" binding="textClass">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/> <preferred-size width="150" height="50"/>
@@ -126,7 +130,7 @@
</constraints> </constraints>
<properties/> <properties/>
</component> </component>
<component id="ebeec" class="javax.swing.JButton" binding="连接Button" default-binding="true"> <component id="ebeec" class="javax.swing.JButton" binding="connectButton">
<constraints> <constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> <grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints> </constraints>

View File

@@ -1,41 +1,90 @@
package com.cfive.classroom.student; package com.cfive.classroom.student;
import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.util.NoConfigException;
import com.cfive.classroom.library.net.StudentNet;
import com.cfive.classroom.library.net.util.MessageObject;
import com.cfive.classroom.library.net.util.ReceiveListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;
public class Center { public class Center {
private JButton Button1; private static final Logger LOGGER = LogManager.getLogger();
private JButton button2; private static final Center center = new Center();
private JButton signInButton;
private JButton raiseHandButton;
private JButton chatButton; private JButton chatButton;
private JPanel rootpanel2; private JPanel rootpanel;
private JTextField textField1;
private JButton changePasswordButton; private JButton changePasswordButton;
private JTextArea textArea1; private JTextArea textClass;
private JButton 连接Button; private JButton connectButton;
static JFrame frame = new JFrame("Center"); private JTextField stuNoText;
private static JFrame frame = new JFrame("Center");
private StudentNet studentNet;
private String host;
private int port;
private String signInCode;
private String stuNo;
private String stuName;
private MessageObject messageObject;
public Center() { public Center() {
//留言
chatButton.addActionListener(new ActionListener() { chatButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Chat chat = new Chat(); Chat chat = new Chat();
chat.start(); chat.start(stuNo,stuName,studentNet);
} }
}); });
//修改密码
changePasswordButton.addActionListener(new ActionListener() { changePasswordButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ChangePassword changePassword = new ChangePassword(); ChangePassword changePassword = new ChangePassword();
changePassword.start(); changePassword.start(stuNoText.getText());
frame.setVisible(false);
} }
}); });
Button1.addActionListener(new ActionListener() { //连接
connectButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String code = JOptionPane.showInputDialog(null,"签到码:","签到",JOptionPane.PLAIN_MESSAGE); Properties properties = new Properties();
if (code.equals("1234")) { try {
properties.load(new BufferedReader(new FileReader("Student/src/main/connect.properties")));
} catch (IOException ex) {
throw new RuntimeException(ex);
}
host = properties.getProperty("host");
port = Integer.parseInt(properties.getProperty("port"));
try {
studentNet = new StudentNet(host,port);
JOptionPane.showMessageDialog(null, "连接成功");
} catch (IOException ex) {
JOptionPane.showMessageDialog(null,"连接失败");
LOGGER.error("IOException",ex);
}
}
});
//签到
signInButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
signInCode = JOptionPane.showInputDialog(null,"签到码:","签到",JOptionPane.PLAIN_MESSAGE);
studentNet.setOnReceiveListener(new ReceiveListener() {
@Override
public void onReceive(MessageObject messageObject) {
if (messageObject.getCode().equals(signInCode)) {
JOptionPane.showMessageDialog(null, "签到成功"); JOptionPane.showMessageDialog(null, "签到成功");
} else { } else {
JOptionPane.showMessageDialog(null,"签到失败"); JOptionPane.showMessageDialog(null,"签到失败");
@@ -43,19 +92,56 @@ public class Center {
} }
}); });
} }
});
public void start(){ //举手
frame.setContentPane(new Center().rootpanel2); raiseHandButton.addActionListener(new ActionListener() {
frame.setBounds(650,300,600,400); @Override
public void actionPerformed(ActionEvent e) {
messageObject = new MessageObject(stuNo, stuName, null, null, null,true);
studentNet.sendMessageThread(messageObject);
JOptionPane.showMessageDialog(null,"你已经向老师举手");
}
});
//随机抽人
studentNet.setOnReceiveListener(new ReceiveListener() {
@Override
public void onReceive(MessageObject messageObject) {
if (messageObject.isState()) {
JOptionPane.showMessageDialog(null,"恭喜以下同学被选中:\n\t\n"+messageObject.getCount());
}
}
});
}
public void start(String num){
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(center.rootpanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false); frame.setResizable(false);
frame.setVisible(true); frame.setVisible(true);
center.stuNoText.setText(num);
stuNo = String.valueOf(stuNoText.getText());
stuName = getName();
LOGGER.info("学号"+stuNo);
LOGGER.info("姓名"+stuName);
}
//获取学生姓名
public String getName(){
String name = null;
try {
name=DatabaseHelper.selectFromStudent(Long.parseLong(stuNoText.getText())).getStuName();
} 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);
}
return name;
} }
public static void main(String[] args) {
frame.setContentPane(new Center().rootpanel2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setResizable(false);
frame.setVisible(false);
}
} }

View File

@@ -55,7 +55,7 @@
</children> </children>
</grid> </grid>
<grid id="5650f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="5650f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="50"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -63,7 +63,7 @@
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="c0f31" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="c0f31" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="20"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="120" height="74"/> <preferred-size width="120" height="74"/>
@@ -74,25 +74,28 @@
<children> <children>
<component id="27845" class="javax.swing.JLabel"> <component id="27845" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Microsoft YaHei" size="20" style="0"/>
<text value="学号"/> <text value="学号"/>
</properties> </properties>
</component> </component>
<component id="6c476" class="javax.swing.JLabel"> <component id="6c476" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Microsoft YaHei" size="20" style="0"/>
<text value="新密码"/> <text value="新密码"/>
</properties> </properties>
</component> </component>
<component id="11d34" class="javax.swing.JLabel"> <component id="11d34" class="javax.swing.JLabel">
<constraints> <constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/> <grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<font name="Microsoft YaHei" size="20" style="0"/>
<text value="确认密码"/> <text value="确认密码"/>
</properties> </properties>
</component> </component>
@@ -106,7 +109,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="4802a" class="javax.swing.JTextField" binding="textField1" default-binding="true"> <component id="4802a" class="javax.swing.JTextField" binding="textNum">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>

View File

@@ -1,58 +1,96 @@
package com.cfive.classroom.student; package com.cfive.classroom.student;
import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent; import java.security.NoSuchAlgorithmException;
import java.awt.event.ActionListener; import java.security.spec.InvalidKeySpecException;
import java.sql.SQLException;
public class ChangePassword { public class ChangePassword {
private static final Logger LOGGER = LogManager.getLogger();
private static final ChangePassword changePassword = new ChangePassword();
private JPanel rootPanel; private JPanel rootPanel;
private JTextField textField1; private JTextField textNum;
private JButton cancel; private JButton cancel;
private JButton confirm; private JButton confirm;
private JPasswordField passwordField1; private JPasswordField passwordField1;
private JPasswordField passwordField2; private JPasswordField passwordField2;
private static JFrame frame = new JFrame("修改密码");
static JFrame frame = new JFrame("ChangePassword"); private String stuNo;
public ChangePassword() { public ChangePassword() {
confirm.addActionListener(e -> { confirm.addActionListener(e -> {
if(check()){ if(check()){
Center.frame.setVisible(true); try {
frame.setVisible(false); DatabaseHelper.changePasswdInStudent(Long.parseLong(stuNo), passwordField1.getPassword().toString());
} catch (NoConfigException ex) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException",e);
} catch (DependenciesNotFoundException ex) {
LOGGER.error("DependenciesNotFoundException",e);
} catch (NoSuchAlgorithmException ex) {
LOGGER.error("NoSuchAlgorithmException",e);
} catch (InvalidKeySpecException ex) {
LOGGER.error("InvalidKeySpecException",e);
}
frame.dispose();
} }
}); });
cancel.addActionListener(e -> { cancel.addActionListener(e -> {
Center.frame.setVisible(true); frame.dispose();
frame.setVisible(false);
}); });
} }
public static void main(String[] args) {
frame.setContentPane(new ChangePassword().rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(false);
}
public void start() {
frame.setContentPane(new ChangePassword().rootPanel);
frame.setBounds(650,300,600,400);
frame.setResizable(false);
// frame.pack();
frame.setVisible(true);
}
private boolean check() { private boolean check() {
String password1,password2; String password1,password2,num;
num = String.valueOf(textNum.getText());
LOGGER.info("传入学号"+stuNo);
LOGGER.info(num);
password1 = String.valueOf(passwordField1.getPassword()); password1 = String.valueOf(passwordField1.getPassword());
password2 = String.valueOf(passwordField2.getPassword()); password2 = String.valueOf(passwordField2.getPassword());
if(num.equals(stuNo)){
if (password1.length()==0 || password2.length()==0) { if (password1.length()==0 || password2.length()==0) {
JOptionPane.showMessageDialog(null,"输入的密码为空"); JOptionPane.showMessageDialog(null,"输入的密码为空");
return false; return false;
} else if (password1.equals(password2) == false) { } else if (!password1.equals(password2)) {
JOptionPane.showMessageDialog(null, "两次输入密码不同"); JOptionPane.showMessageDialog(null, "两次输入密码不同");
return false; return false;
} else return true; } else return true;
} }
else {
JOptionPane.showMessageDialog(null,"学号非本人学号");
return false;
}
}
public void start(String stuNo) {
frame.setContentPane(changePassword.rootPanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);
changePassword.stuNo = stuNo;
LOGGER.info(changePassword.stuNo);
}
public static void main(String[] args) {
frame.setContentPane(changePassword.rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(false);
}
} }

View File

@@ -8,7 +8,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="70cf5" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="70cf5" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -16,41 +16,42 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<grid id="2f7dd" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="2f7dd" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="3ab11" class="javax.swing.JButton" binding="发送Button" default-binding="true"> <component id="3ab11" class="javax.swing.JButton" binding="sendButton">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="50"/>
</grid>
</constraints> </constraints>
<properties> <properties>
<text value=" 发送"/> <text value=" 发送"/>
</properties> </properties>
</component> </component>
</children> <scrollpane id="a60c9">
</grid>
<grid id="f0f0b" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="-1" height="50"/>
</grid>
</constraints> </constraints>
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="61378" class="javax.swing.JTextField" binding="textField1" default-binding="true"> <component id="8c36e" class="javax.swing.JTextArea" binding="sendText">
<constraints> <constraints/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="9" fill="1" indent="0" use-parent-layout="false"> <properties>
<preferred-size width="150" height="-1"/> <editable value="true"/>
</grid> </properties>
</constraints>
<properties/>
</component> </component>
</children> </children>
</scrollpane>
</children>
</grid> </grid>
</children> </children>
</grid> </grid>
@@ -58,13 +59,17 @@
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties/> <properties>
<background color="-1"/>
</properties>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="13f7a" class="javax.swing.JTextArea" binding="textArea1" default-binding="true"> <component id="13f7a" class="javax.swing.JTextArea" binding="receiveText">
<constraints/> <constraints/>
<properties> <properties>
<background color="-1"/>
<editable value="false"/> <editable value="false"/>
<text value=""/>
</properties> </properties>
</component> </component>
</children> </children>

View File

@@ -1,23 +1,55 @@
package com.cfive.classroom.student; package com.cfive.classroom.student;
import com.cfive.classroom.library.net.ReceiveThread;
import com.cfive.classroom.library.net.StudentNet;
import com.cfive.classroom.library.net.util.MessageObject;
import com.cfive.classroom.library.net.util.ReceiveListener;
import javax.swing.*; import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Properties;
public class Chat { public class Chat {
private static final Chat chat = new Chat();
private JPanel panel1; private JPanel panel1;
private JTextField textField1; private JButton sendButton;
private JButton 发送Button; private JTextArea receiveText;
private JTextArea textArea1; private JTextArea sendText;
static JFrame frame = new JFrame("test"); private static JFrame frame = new JFrame("留言");
public void start(){ private StudentNet studentNet;
frame.setContentPane(new Chat().panel1); private String stuNo, stuName,host;
frame.setBounds(650,300,600,400); private int port;
frame.setVisible(true);
}
public static void main(String[] args) {
public Chat() {
//发送消息
sendButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(String.valueOf(sendText.getText())!=null) {
studentNet.sendMessageThread(new MessageObject(stuNo, stuName, null, String.valueOf(sendText.getText()), null, false));
}
else{
JOptionPane.showMessageDialog(null,"无发送内容");
}
}
});
//接收消息
studentNet.setOnReceiveListener(new ReceiveListener() {
@Override
public void onReceive(MessageObject messageObject) {
receiveText.setText("教师:\n"+messageObject.getMessage());
}
});
}
public void start(String num, String name,StudentNet studentNet1) {
frame.setContentPane(new Chat().panel1); frame.setContentPane(new Chat().panel1);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600, 400);
// frame.pack(); frame.setLocationRelativeTo(null);
frame.setVisible(false); frame.setVisible(true);
chat.stuNo = num;
chat.stuName = name;
chat.studentNet = studentNet1;
} }
} }

View File

@@ -52,7 +52,7 @@
<text value="学号"/> <text value="学号"/>
</properties> </properties>
</component> </component>
<component id="20676" class="javax.swing.JTextField" binding="textField1" default-binding="true"> <component id="20676" class="javax.swing.JTextField" binding="stuNoText">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>
@@ -72,7 +72,7 @@
<properties/> <properties/>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="2a28" class="javax.swing.JLabel"> <component id="2a28" class="javax.swing.JLabel" binding="password">
<constraints> <constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
@@ -81,7 +81,7 @@
<text value="密码"/> <text value="密码"/>
</properties> </properties>
</component> </component>
<component id="59402" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true"> <component id="59402" class="javax.swing.JPasswordField" binding="passwordText">
<constraints> <constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/> <preferred-size width="150" height="-1"/>

View File

@@ -1,47 +1,78 @@
package com.cfive.classroom.student; 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 javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; 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{ public class MainWindow{
private static final MainWindow mainWindow = new MainWindow();
private JPanel rootPanel; private JPanel rootPanel;
private JLabel title; private JLabel title;
private JTextField textField1; private JTextField stuNoText;
private JPasswordField passwordField1; private JPasswordField passwordText;
private JButton login; 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() { public MainWindow() {
//登录按钮
login.addActionListener(new ActionListener() { login.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if(check()){ if(check()){
Center center = new Center(); Center center = new Center();
center.start(); center.start(String.valueOf(stuNoText.getText()));
frame.setVisible(false); frame.dispose();
} }
} }
}); });
} }
public boolean check(){ public boolean check(){
String password = new String(passwordField1.getPassword()); String stuPassword = new String(passwordText.getPassword());
if (textField1.getText() == null || password.length() == 0) { String stuNo = new String(stuNoText.getText());
LOGGER.info(Long.valueOf(stuNo));
//判断密码
if (stuNo.length() == 0 || stuPassword.length() == 0) {
JOptionPane.showMessageDialog(null, "账号密码不能为空"); JOptionPane.showMessageDialog(null, "账号密码不能为空");
return false; return false;
} else { } 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) { public static void main(String[] args) {
FlatLightLaf.setup();
frame.setContentPane(new MainWindow().rootPanel); frame.setContentPane(mainWindow.rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,400);
// frame.pack(); frame.setTitle("登录");
frame.setBounds(650,300,600,400); frame.setLocationRelativeTo(null);
frame.setVisible(true); frame.setVisible(true);
frame.setResizable(false); frame.setResizable(false);
} }

View File

@@ -0,0 +1,20 @@
package com.cfive.classroom.student;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
public class MyTest {
private static final Logger LOGGER = LogManager.getLogger();
@Test
void firstTest() {
LOGGER.info("This is a log");
try {
throw new Exception("exception");
} catch (Exception e) {
LOGGER.error("Err", e);
}
}
}

7
mysql.properties Normal file
View File

@@ -0,0 +1,7 @@
#MySQL Configuration
#Thu Jun 09 22:24:30 CST 2022
port=3306
password=class_five
database=class
ip=10.14.0.7
username=class