mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 04:01:27 +08:00
StudentUI:Center,interface,Chat
TeacherUI:Attend,interface,CheckIn,ClassList,SendMessage,SignIn,TeacherTest
This commit is contained in:
@@ -18,6 +18,8 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Center {
|
||||
@@ -41,7 +43,9 @@ public class Center {
|
||||
private String getSignInCode;
|
||||
private MessageObject messageObject;
|
||||
private boolean flag = false;
|
||||
private ChatReceiveListener chatReceiveListener;
|
||||
private Chat chat;
|
||||
private List<String> messageAll = new ArrayList<>();
|
||||
|
||||
public Center(String stuNo) {
|
||||
this.stuNo = stuNo;
|
||||
@@ -56,10 +60,9 @@ public class Center {
|
||||
|
||||
if (studentNet != null) {
|
||||
if (flag == false) {
|
||||
chat = new Chat(studentNet,stuNo,stuName);
|
||||
chat = new Chat(studentNet,stuNo,stuName,chatReceiveListener);
|
||||
flag = true;
|
||||
}
|
||||
|
||||
chat.start();
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null,"没有连接至教师");
|
||||
@@ -104,6 +107,20 @@ public class Center {
|
||||
}
|
||||
}
|
||||
});
|
||||
chatReceiveListener = new ChatReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
//签到
|
||||
if (messageObject.getMessageType() == MessageType.CheckIn) {
|
||||
getSignInCode = messageObject.getCode();
|
||||
LOGGER.info(messageObject.getCode());
|
||||
}
|
||||
//随机抽人
|
||||
if (messageObject.getMessageType() == MessageType.Select) {
|
||||
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + messageObject.getCount());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null,"连接失败");
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Chat {
|
||||
private static JFrame frame = new JFrame("留言");
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public Chat(StudentNet studentNet,String stuNo,String stuName) {
|
||||
public Chat(StudentNet studentNet,String stuNo,String stuName,ChatReceiveListener chatReceiveListener) {
|
||||
//发送消息
|
||||
sendButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@@ -46,6 +46,7 @@ public class Chat {
|
||||
if(messageObject.getMessageType()==MessageType.ChatToAll){
|
||||
receiveText.append("教师:"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+"\n");
|
||||
}
|
||||
chatReceiveListener.onReceive(messageObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.cfive.classroom.student;
|
||||
|
||||
import com.cfive.classroom.library.net.util.MessageObject;
|
||||
|
||||
public interface ChatReceiveListener {
|
||||
void onReceive(MessageObject messageObject);
|
||||
}
|
||||
@@ -27,51 +27,24 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Attend {
|
||||
private static final Attend attend = new Attend();
|
||||
private static final JFrame frame = new JFrame("考勤情况");
|
||||
private JPanel rootPanel;
|
||||
private JTabbedPane tabbedPane1;
|
||||
private final Object[] t1_columnTitle = {"考勤号","学号", "姓名", "签到时间","签到状态"};
|
||||
private final Object[] t1_columnTitle = {"考勤号", "学号", "姓名", "签到时间", "签到状态"};
|
||||
private final Object[] t2_columnTitle = {"考勤号", "学号", "姓名", "签到状态"};
|
||||
private JTable table_already;
|
||||
private JTable table_undo;
|
||||
private JButton bt_refresh;
|
||||
private TeacherNet teacherNet;
|
||||
private String courseID;
|
||||
private final List<Attendance> attendancesList = new ArrayList<>();
|
||||
private final List<Attendance> alreadyList = new ArrayList<>();
|
||||
private final List<Attendance> undoList = new ArrayList<>();
|
||||
private DefaultTableModel undoTableModel,alreadyTableModel;
|
||||
private DefaultTableModel undoTableModel, alreadyTableModel;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public Attend() {
|
||||
//学生签到信息监听
|
||||
if(teacherNet!=null){
|
||||
teacherNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if(messageObject.getStuNo()!=null){
|
||||
//判断该信息类型是否为签到并且签到状态是否为已签
|
||||
if (messageObject.getMessageType() == MessageType.CheckIn && messageObject.getAttStatus() == AttStatus.signed) {
|
||||
try {
|
||||
//将学生签到状态修改进数据表中
|
||||
DatabaseHelper.updateAttendance(messageObject.getStuNo(), messageObject.getAttStatus(),messageObject.getLocalDateTime());
|
||||
} 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);
|
||||
}
|
||||
//刷新表格
|
||||
bt_refresh.doClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Attend(TeacherNet teacherNet, String courseID) {
|
||||
this.courseID = courseID;
|
||||
|
||||
//已签表格的鼠标点击事件
|
||||
table_already.addMouseListener(new MouseAdapter() {
|
||||
@@ -92,6 +65,7 @@ public class Attend {
|
||||
table_already.getModel().setValueAt(modifyStat, row, col);
|
||||
//将修改在数据库中更改
|
||||
try {
|
||||
LOGGER.info("test");
|
||||
DatabaseHelper.updateAttendance(String.valueOf(table_already.getModel().getValueAt(row, 0)), attStatus, null);
|
||||
} catch (NoConfigException ex) {
|
||||
JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);
|
||||
@@ -143,7 +117,7 @@ public class Attend {
|
||||
LOGGER.error("DependenciesNotFoundException", e);
|
||||
}
|
||||
//如果修改为已签则刷新表格
|
||||
if(attStatus==AttStatus.signed){
|
||||
if (attStatus == AttStatus.signed) {
|
||||
bt_refresh.doClick();
|
||||
}
|
||||
|
||||
@@ -156,95 +130,37 @@ public class Attend {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//清空列表
|
||||
((DefaultTableModel)table_already.getModel()).setRowCount(0);
|
||||
((DefaultTableModel)table_undo.getModel()).setRowCount(0);
|
||||
((DefaultTableModel) table_already.getModel()).setRowCount(0);
|
||||
((DefaultTableModel) table_undo.getModel()).setRowCount(0);
|
||||
attendancesList.clear();
|
||||
alreadyList.clear();
|
||||
undoList.clear();
|
||||
//重新加载
|
||||
try {
|
||||
attendancesList.addAll(DatabaseHelper.selectAttendanceByCourse(Long.parseLong(courseID))); //导入该课程考勤名单
|
||||
for (Attendance attendance : attendancesList) {
|
||||
if (attendance.getAttStatus() == AttStatus.signed) { //筛选出已签到的考勤列表
|
||||
alreadyList.add(attendance);
|
||||
} else {
|
||||
undoList.add(attendance);
|
||||
}
|
||||
}
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (NoConfigException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (SQLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
//已签考勤表格
|
||||
alreadyTableModel = new DefaultTableModel(t1_columnTitle, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (alreadyList != null) {
|
||||
for (Attendance attendance : alreadyList) {
|
||||
String attID = attendance.getAttID();
|
||||
String stuID = String.valueOf(attendance.getStudent().getStuID());
|
||||
String stuName = String.valueOf(attendance.getStudent().getStuName());
|
||||
LocalDateTime attTime = attendance.getAttTime();
|
||||
AttStatus attStatus = attendance.getAttStatus();
|
||||
String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
Object row[] = {attID,stuID, stuName, attTime1,String.valueOf(attStatus)};
|
||||
alreadyTableModel.addRow(row);
|
||||
}
|
||||
}
|
||||
attend.table_already.setModel(alreadyTableModel);
|
||||
|
||||
//未签考勤表格
|
||||
undoTableModel = new DefaultTableModel(t2_columnTitle, 0);
|
||||
for (Attendance attendance : undoList) {
|
||||
String attID = attendance.getAttID();
|
||||
String stuID = String.valueOf(attendance.getStudent().getStuID());
|
||||
String stuName = String.valueOf(attendance.getStudent().getStuName());
|
||||
AttStatus attStatus = attendance.getAttStatus();
|
||||
Object row[] = {attID, stuID, stuName, String.valueOf(attStatus)};
|
||||
undoTableModel.addRow(row);
|
||||
}
|
||||
attend.table_undo.setModel(undoTableModel);
|
||||
//设置第一列隐藏
|
||||
TableColumn tableColumn = attend.table_undo.getColumnModel().getColumn(0);
|
||||
tableColumn.setWidth(0);
|
||||
tableColumn.setMinWidth(0);
|
||||
tableColumn.setPreferredWidth(0);
|
||||
tableColumn.setMaxWidth(0);
|
||||
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
|
||||
attend.table_undo.setCellSelectionEnabled(true);
|
||||
|
||||
readData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(attend.rootPanel);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public void start(TeacherNet teacherNet1, String courseID) {
|
||||
frame.setContentPane(attend.rootPanel);
|
||||
public void start() {
|
||||
frame.setContentPane(rootPanel);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
attend.teacherNet = teacherNet1;
|
||||
attend.courseID = courseID;
|
||||
|
||||
readData();
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void readData(){
|
||||
try {
|
||||
attendancesList.addAll(DatabaseHelper.selectAttendanceByCourse(Long.parseLong(courseID))); //导入该课程考勤名单
|
||||
LOGGER.debug("attendanceList:" + attendancesList);
|
||||
for (Attendance attendance : attendancesList) {
|
||||
if (attendance.getAttStatus() == AttStatus.signed) { //筛选出已签到的考勤列表
|
||||
alreadyList.add(attendance);
|
||||
@@ -268,7 +184,7 @@ public class Attend {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (alreadyList != null) {
|
||||
if (!alreadyList.isEmpty()) {
|
||||
for (Attendance attendance : alreadyList) {
|
||||
String attID = attendance.getAttID();
|
||||
String stuID = String.valueOf(attendance.getStudent().getStuID());
|
||||
@@ -276,23 +192,24 @@ public class Attend {
|
||||
LocalDateTime attTime = attendance.getAttTime();
|
||||
AttStatus attStatus = attendance.getAttStatus();
|
||||
String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
Object row[] = {attID,stuID, stuName, attTime1,String.valueOf(attStatus)};
|
||||
Object row[] = {attID, stuID, stuName, attTime1, String.valueOf(attStatus)};
|
||||
alreadyTableModel.addRow(row);
|
||||
}
|
||||
}
|
||||
attend.table_already.setModel(alreadyTableModel);
|
||||
TableColumn tableColumn1 = attend.table_already.getColumnModel().getColumn(0);
|
||||
table_already.setModel(alreadyTableModel);
|
||||
//设置未签表格的第一列考勤号隐藏
|
||||
TableColumn tableColumn1 = table_already.getColumnModel().getColumn(0);
|
||||
tableColumn1.setWidth(0);
|
||||
tableColumn1.setMinWidth(0);
|
||||
tableColumn1.setPreferredWidth(0);
|
||||
tableColumn1.setMaxWidth(0);
|
||||
attend.table_already.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
attend.table_already.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
|
||||
attend.table_already.setCellSelectionEnabled(true);
|
||||
table_already.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
table_already.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
|
||||
table_already.setCellSelectionEnabled(true);
|
||||
|
||||
//未签考勤表格
|
||||
if(undoList!=null){ //判断该课程是否有学生名单
|
||||
undoTableModel = new DefaultTableModel(t2_columnTitle, 0){
|
||||
if (!undoList.isEmpty()) { //判断该课程是否有学生名单
|
||||
undoTableModel = new DefaultTableModel(t2_columnTitle, 0) {
|
||||
@Override
|
||||
public boolean isCellEditable(int row, int column) {
|
||||
return false;
|
||||
@@ -306,25 +223,20 @@ public class Attend {
|
||||
Object row[] = {attID, stuID, stuName, String.valueOf(attStatus)};
|
||||
undoTableModel.addRow(row);
|
||||
}
|
||||
attend.table_undo.setModel(undoTableModel);
|
||||
table_undo.setModel(undoTableModel);
|
||||
//设置未签表格的第一列考勤号隐藏
|
||||
TableColumn tableColumn2 = attend.table_undo.getColumnModel().getColumn(0);
|
||||
TableColumn tableColumn2 = table_undo.getColumnModel().getColumn(0);
|
||||
tableColumn2.setWidth(0);
|
||||
tableColumn2.setMinWidth(0);
|
||||
tableColumn2.setPreferredWidth(0);
|
||||
tableColumn2.setMaxWidth(0);
|
||||
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
|
||||
attend.table_undo.setCellSelectionEnabled(true);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(null,"该课程学生名单未导入","提醒!",JOptionPane.INFORMATION_MESSAGE);
|
||||
table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
|
||||
table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
|
||||
table_undo.setCellSelectionEnabled(true);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "该课程学生名单未导入", "提醒!", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.net.util.MessageObject;
|
||||
|
||||
public interface ChatReceiveListener {
|
||||
void onReceive(MessageObject messageObject);
|
||||
}
|
||||
@@ -7,13 +7,9 @@ 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.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class CheckIn {
|
||||
private static final CheckIn checkIn = new CheckIn();
|
||||
private static final JFrame frame = new JFrame("发布签到码");
|
||||
private JPanel rootPanel;
|
||||
private JTextField textField1;
|
||||
@@ -23,10 +19,9 @@ public class CheckIn {
|
||||
private JButton bt_confim;
|
||||
private JButton bt_cancel;
|
||||
private String n1, n2, n3, n4, number;
|
||||
private TeacherNet teacherNet;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public CheckIn() {
|
||||
public CheckIn(TeacherNet teacherNet) {
|
||||
//取消按钮的监听
|
||||
bt_cancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@@ -71,16 +66,41 @@ public class CheckIn {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//回车键的监听:发布签到码
|
||||
textField4.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyChar()==KeyEvent.VK_ENTER){
|
||||
//获取签到码广播出去
|
||||
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
||||
if (number != null) {
|
||||
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
||||
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
||||
frame.setVisible(false);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "签到码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
|
||||
//确定按钮的点击事件
|
||||
bt_confim.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//获取签到码广播出去
|
||||
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
||||
if (number != null) {
|
||||
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
||||
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
||||
frame.dispose();
|
||||
frame.setVisible(false);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "签到码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
@@ -90,18 +110,14 @@ public class CheckIn {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(checkIn.rootPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(false);
|
||||
|
||||
}
|
||||
|
||||
public void start(TeacherNet teacherNet1) {
|
||||
frame.setContentPane(checkIn.rootPanel);
|
||||
public void start() {
|
||||
frame.setContentPane(rootPanel);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
checkIn.teacherNet = teacherNet1;
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ClassList {
|
||||
bt_enter.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
LOGGER.info(workerNo);
|
||||
if (!Objects.equals(classList.comboBox.getSelectedItem(), "--请选择--")) { //判断是否有选择内容
|
||||
String select = classList.comboBox.getSelectedItem().toString();
|
||||
courseID = select.substring(0, select.indexOf(" "));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.database.DatabaseHelper;
|
||||
import com.cfive.classroom.library.database.bean.AttStatus;
|
||||
import com.cfive.classroom.library.database.bean.Student;
|
||||
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
|
||||
import com.cfive.classroom.library.database.util.NoConfigException;
|
||||
@@ -16,6 +17,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.*;
|
||||
import java.sql.SQLException;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
@@ -32,10 +34,12 @@ public class Main {
|
||||
private JTextField subName_show;
|
||||
private String workNo, courseID;
|
||||
private final List<Student> studentList = new ArrayList<>();
|
||||
private final List<String> messageAll = new ArrayList<>();
|
||||
;
|
||||
private String[] student;
|
||||
private TeacherNet teacherNet;
|
||||
private final Logger LOGGER = LogManager.getLogger();
|
||||
private ChatReceiveListener chatReceiveListener;
|
||||
|
||||
public Main() {
|
||||
|
||||
@@ -59,8 +63,8 @@ public class Main {
|
||||
bt_sendMessage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SendMessage sendMessage = new SendMessage();
|
||||
sendMessage.start(teacherNet);
|
||||
SendMessage sendMessage = new SendMessage(teacherNet,chatReceiveListener);
|
||||
sendMessage.start(messageAll);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,8 +72,8 @@ public class Main {
|
||||
bt_checkIn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CheckIn checkIn = new CheckIn();
|
||||
checkIn.start(teacherNet);
|
||||
CheckIn checkIn = new CheckIn(teacherNet);
|
||||
checkIn.start();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -77,8 +81,8 @@ public class Main {
|
||||
bt_attendance.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Attend attend = new Attend();
|
||||
attend.start(teacherNet, courseID);
|
||||
Attend attend = new Attend(teacherNet, courseID);
|
||||
attend.start();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -124,7 +128,7 @@ public class Main {
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count);
|
||||
//将选人结果群发出去
|
||||
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, null, null,MessageType.Select));
|
||||
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, null, null, MessageType.Select));
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "学生名单未导入", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
@@ -152,25 +156,81 @@ public class Main {
|
||||
});
|
||||
|
||||
//主界面线程监听
|
||||
if(teacherNet!=null){
|
||||
// if (teacherNet != null) {
|
||||
teacherNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if(messageObject.getStuNo()!=null){
|
||||
if (messageObject.getStuNo() != null) {
|
||||
//学生端举手监听
|
||||
if (messageObject.getMessageType() == MessageType.RaiseHand) {
|
||||
JOptionPane.showMessageDialog(null, "学生 "+messageObject.getStuName() + " 向您举手", "温馨提示!", JOptionPane.INFORMATION_MESSAGE);
|
||||
LOGGER.info("举手test");
|
||||
JOptionPane.showMessageDialog(null, "学生 " + messageObject.getStuName() + " 向您举手", "温馨提示!", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
//学生留言监听
|
||||
if (messageObject.getMessageType() == MessageType.Chat) {
|
||||
LOGGER.info("留言test");
|
||||
JOptionPane.showMessageDialog(null, messageObject.getMessage(), "学生 " + messageObject.getStuName() + " 向您留言", JOptionPane.INFORMATION_MESSAGE);
|
||||
messageAll.add("学生 "+messageObject.getStuName()+": "+messageObject.getLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+'\n');
|
||||
}
|
||||
//学生签到信息监听,判断该信息类型是否为签到并且签到状态是否为已签
|
||||
if (messageObject.getMessageType() == MessageType.CheckIn && messageObject.getAttStatus() == AttStatus.signed) {
|
||||
try {
|
||||
LOGGER.info("收到签到 " + messageObject.toString());
|
||||
//将学生签到状态修改进数据表中
|
||||
String attID = DatabaseHelper.selectFromAttendance(Long.parseLong(messageObject.getStuNo()), Long.parseLong(courseID)).getAttID();
|
||||
DatabaseHelper.updateAttendance(attID, messageObject.getAttStatus(), messageObject.getLocalDateTime());
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
chatReceiveListener = new ChatReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.getStuNo() != null) {
|
||||
//学生端举手监听
|
||||
if (messageObject.getMessageType() == MessageType.RaiseHand) {
|
||||
LOGGER.info("举手test");
|
||||
JOptionPane.showMessageDialog(null, "学生 " + messageObject.getStuName() + " 向您举手", "温馨提示!", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
//学生留言监听
|
||||
if (messageObject.getMessageType() == MessageType.Chat) {
|
||||
LOGGER.info("留言test");
|
||||
JOptionPane.showMessageDialog(null, messageObject.getMessage(), "学生 " + messageObject.getStuName() + " 向您留言", JOptionPane.INFORMATION_MESSAGE);
|
||||
messageAll.add("学生 "+messageObject.getStuName()+": "+messageObject.getLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+'\n');
|
||||
}
|
||||
//学生签到信息监听,判断该信息类型是否为签到并且签到状态是否为已签
|
||||
if (messageObject.getMessageType() == MessageType.CheckIn && messageObject.getAttStatus() == AttStatus.signed) {
|
||||
try {
|
||||
LOGGER.info("收到签到 " + messageObject.toString());
|
||||
//将学生签到状态修改进数据表中
|
||||
String attID = DatabaseHelper.selectFromAttendance(Long.parseLong(messageObject.getStuNo()), Long.parseLong(courseID)).getAttID();
|
||||
DatabaseHelper.updateAttendance(attID, messageObject.getAttStatus(), messageObject.getLocalDateTime());
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
// }
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -187,7 +247,6 @@ public class Main {
|
||||
frame.setResizable(false);
|
||||
main.workNo = workerNo;
|
||||
main.courseID = courseID;
|
||||
//开启主界面即读取端口号
|
||||
main.workNo_show.setText(workerNo);
|
||||
main.subName_show.setText(subName);
|
||||
|
||||
|
||||
@@ -6,24 +6,22 @@ import com.cfive.classroom.library.net.util.MessageType;
|
||||
import com.cfive.classroom.library.net.util.ReceiveListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SendMessage {
|
||||
private static final SendMessage sendMessage=new SendMessage();
|
||||
|
||||
private static JFrame frame = new JFrame("发送消息");
|
||||
private static final JFrame frame = new JFrame("发送消息");
|
||||
private JPanel rootPanel;
|
||||
private JTextArea messageInput;
|
||||
private JButton bt_sendMessage;
|
||||
private JTextArea messageShow;
|
||||
private TeacherNet teacherNet;
|
||||
|
||||
public SendMessage() {
|
||||
public SendMessage(TeacherNet teacherNet,ChatReceiveListener chatReceiveListener) {
|
||||
//接收学生发过来的留言
|
||||
if(teacherNet!=null){
|
||||
teacherNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@@ -31,10 +29,10 @@ public class SendMessage {
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if(messageObject.getStuNo()!=null){
|
||||
if(messageObject.getMessageType()==MessageType.Chat){
|
||||
LocalDateTime sendTime = LocalDateTime.now();
|
||||
messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+'\n');
|
||||
messageShow.append("学生 "+messageObject.getStuName()+": "+messageObject.getLocalDateTime().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+'\n');
|
||||
}
|
||||
}
|
||||
chatReceiveListener.onReceive(messageObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -60,19 +58,17 @@ public class SendMessage {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(sendMessage.rootPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(false);
|
||||
}
|
||||
|
||||
public void start(TeacherNet teacherNet1){
|
||||
frame.setContentPane(sendMessage.rootPanel);
|
||||
public void start(List<String> messageFromStu){
|
||||
frame.setContentPane(rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
for (String message : messageFromStu) {
|
||||
messageShow.append(message);
|
||||
}
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
sendMessage.teacherNet = teacherNet1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.apache.logging.log4j.Logger;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.net.NoRouteToHostException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
@@ -34,52 +36,83 @@ public class SignIn {
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
|
||||
//回车键登录监听
|
||||
sigIn.password_input.addKeyListener(new KeyListener() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(e.getKeyChar()==KeyEvent.VK_ENTER){
|
||||
if(sigIn.isPwRight()){
|
||||
ClassList classList = new ClassList();
|
||||
classList.start(sigIn.workerNo); //将工号传参到下一个界面
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
//登录按钮监听
|
||||
sigIn.login_Button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
sigIn.workerNo=String.valueOf(sigIn.workerNo_input.getText());
|
||||
sigIn.password=String.valueOf(sigIn.password_input.getPassword());
|
||||
if(sigIn.workerNo.length()==0||sigIn.password.length()==0){ //判断用户名和密码是否为空
|
||||
JOptionPane.showMessageDialog(null,"用户名和密码不能为空","提示!!",JOptionPane.ERROR_MESSAGE);
|
||||
}else{
|
||||
//根据输入的工号和密码利用加盐位进行判断
|
||||
try {
|
||||
if (DatabaseHelper.checkPasswdInTeacher(Long.valueOf(sigIn.workerNo), sigIn.password)) {
|
||||
ClassList classList = new ClassList();
|
||||
classList.start(sigIn.workerNo); //将工号传参到下一个界面
|
||||
frame.setVisible(false);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "密码错误,请重新输入", "错误!!", JOptionPane.ERROR_MESSAGE);
|
||||
sigIn.password_input.setText(""); //清空输入框内容
|
||||
}
|
||||
isConnectedToDatabase = true;
|
||||
} 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) {
|
||||
JOptionPane.showMessageDialog(null, "未查询到该数据", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("DependenciesNotFoundException", e);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
LOGGER.error("NoSuchAlgorithmException", e);
|
||||
} catch (InvalidKeySpecException ex) {
|
||||
LOGGER.error("InvalidKeySpecException", e);
|
||||
} finally {
|
||||
if (!isConnectedToDatabase) {
|
||||
JOptionPane.showMessageDialog(null, "无法连接到数据库", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
isConnectedToDatabase = false;
|
||||
}
|
||||
if(sigIn.isPwRight()){
|
||||
ClassList classList = new ClassList();
|
||||
classList.start(sigIn.workerNo); //将工号传参到下一个界面
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
private boolean isPwRight(){
|
||||
sigIn.workerNo=String.valueOf(sigIn.workerNo_input.getText());
|
||||
sigIn.password=String.valueOf(sigIn.password_input.getPassword());
|
||||
if(sigIn.workerNo.length()==0||sigIn.password.length()==0){ //判断用户名和密码是否为空
|
||||
JOptionPane.showMessageDialog(null,"用户名和密码不能为空","提示!!",JOptionPane.ERROR_MESSAGE);
|
||||
return false;
|
||||
}else{
|
||||
//根据输入的工号和密码利用加盐位进行判断
|
||||
try {
|
||||
if (DatabaseHelper.checkPasswdInTeacher(Long.valueOf(sigIn.workerNo), sigIn.password)) {
|
||||
isConnectedToDatabase = true;
|
||||
return true;
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "密码错误,请重新输入", "错误!!", JOptionPane.ERROR_MESSAGE);
|
||||
sigIn.password_input.setText(""); //清空输入框内容
|
||||
isConnectedToDatabase = true;
|
||||
return false;
|
||||
}
|
||||
} catch (NoConfigException ex) {
|
||||
JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("No configuration", ex);
|
||||
} catch (SQLException ex) {
|
||||
LOGGER.error("SQLException", ex);
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
JOptionPane.showMessageDialog(null, "未查询到该数据", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("DependenciesNotFoundException", ex);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
LOGGER.error("NoSuchAlgorithmException", ex);
|
||||
} catch (InvalidKeySpecException ex) {
|
||||
LOGGER.error("InvalidKeySpecException", ex);
|
||||
} finally {
|
||||
if (!isConnectedToDatabase) {
|
||||
JOptionPane.showMessageDialog(null, "无法连接到数据库", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
isConnectedToDatabase = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class TeacherTest {
|
||||
@Test
|
||||
void modifyPw(){
|
||||
try {
|
||||
DatabaseHelper.changePasswdInTeacher(Long.valueOf("1002"),"10021002");
|
||||
DatabaseHelper.changePasswdInTeacher(Long.valueOf("1004"),"10041004");
|
||||
} catch (NoConfigException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (SQLException e) {
|
||||
|
||||
Reference in New Issue
Block a user