Init student's Center,Chat,MainWindow,MyTest

This commit is contained in:
GGB
2022-06-12 00:50:50 +08:00
parent b36995ba91
commit 116cbc36c5
4 changed files with 25 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
package com.cfive.classroom.student;
import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.bean.AttStatus;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException;
import com.cfive.classroom.library.net.StudentNet;
import com.cfive.classroom.library.net.util.MessageObject;
@@ -16,6 +18,7 @@ import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.Properties;
public class Center {
@@ -86,6 +89,7 @@ public class Center {
@Override
public void onReceive(MessageObject messageObject) {
if (messageObject.getMessageType()==MessageType.CheckIn&&messageObject.getCode().equals(signInCode)) {
studentNet.sendMessageThread(new MessageObject(stuNo,stuName,null, null,null,AttStatus.signed,LocalDateTime.now(),null));
JOptionPane.showMessageDialog(null, "签到成功");
} else {
JOptionPane.showMessageDialog(null,"签到失败");
@@ -99,7 +103,7 @@ public class Center {
raiseHandButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
messageObject = new MessageObject(stuNo, stuName, null, null, null, MessageType.RaiseHand);
messageObject = new MessageObject(stuNo, stuName, null, null, null, null,null,MessageType.RaiseHand);
studentNet.sendMessageThread(messageObject);
JOptionPane.showMessageDialog(null,"你已经向老师举手");
}

View File

@@ -5,10 +5,13 @@ import com.cfive.classroom.library.net.StudentNet;
import com.cfive.classroom.library.net.util.MessageObject;
import com.cfive.classroom.library.net.util.MessageType;
import com.cfive.classroom.library.net.util.ReceiveListener;
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.time.LocalDateTime;
import java.util.Properties;
public class Chat {
@@ -21,6 +24,7 @@ public class Chat {
private StudentNet studentNet;
private String stuNo, stuName,host;
private int port;
private static final Logger LOGGER = LogManager.getLogger();
public Chat() {
@@ -29,7 +33,8 @@ public class Chat {
@Override
public void actionPerformed(ActionEvent e) {
if(String.valueOf(sendText.getText())!=null) {
studentNet.sendMessageThread(new MessageObject(stuNo, stuName, null, String.valueOf(sendText.getText()), null, MessageType.Chat));
LOGGER.info(LocalDateTime.now());
studentNet.sendMessageThread(new MessageObject(stuNo, stuName, null, String.valueOf(sendText.getText()) ,null,null,LocalDateTime.now(),MessageType.Chat));
}
else{
JOptionPane.showMessageDialog(null,"无发送内容","错误!",JOptionPane.ERROR_MESSAGE);
@@ -41,7 +46,7 @@ public class Chat {
@Override
public void onReceive(MessageObject messageObject) {
if(messageObject.getMessageType()==MessageType.ChatToAll){
receiveText.setText("教师:\n"+messageObject.getMessage());
receiveText.append("教师:\n"+messageObject.getMessage()+"\n");
}
}
});

View File

@@ -28,6 +28,7 @@ public class MainWindow{
private static final Logger LOGGER = LogManager.getLogger();
public MainWindow() {
//登录按钮
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -40,17 +41,19 @@ public class MainWindow{
});
}
public boolean check(){
String stuPassword = new String(passwordText.getPassword());
String stuNo = new String(stuNoText.getText());
String stuPassword = String.valueOf(passwordText.getPassword());
String stuNo = String.valueOf(stuNoText.getText());
LOGGER.info(Long.valueOf(stuNo));
LOGGER.info(stuPassword);
//判断密码
if (stuNo.length() == 0 || stuPassword.length() == 0) {
JOptionPane.showMessageDialog(null, "账号密码不能为空");
return false;
} else {
boolean checkPassword=false;
boolean checkPassword = false;
try {
checkPassword=DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo),stuPassword);
LOGGER.info(DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword));
checkPassword = DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword);
} catch (NoConfigException e) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);