mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 02:21:26 +08:00
TeacherUI reModify by 6.11 4:00
This commit is contained in:
@@ -4,6 +4,7 @@ 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.MessageType;
|
||||
import com.cfive.classroom.library.net.util.ReceiveListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -84,7 +85,7 @@ public class Center {
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.getCode().equals(signInCode)) {
|
||||
if (messageObject.getMessageType()==MessageType.CheckIn&&messageObject.getCode().equals(signInCode)) {
|
||||
JOptionPane.showMessageDialog(null, "签到成功");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null,"签到失败");
|
||||
@@ -98,7 +99,7 @@ public class Center {
|
||||
raiseHandButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
messageObject = new MessageObject(stuNo, stuName, null, null, null,true);
|
||||
messageObject = new MessageObject(stuNo, stuName, null, null, null, MessageType.RaiseHand);
|
||||
studentNet.sendMessageThread(messageObject);
|
||||
JOptionPane.showMessageDialog(null,"你已经向老师举手");
|
||||
}
|
||||
@@ -107,7 +108,7 @@ public class Center {
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.isState()) {
|
||||
if (messageObject.getMessageType()==MessageType.Select) {
|
||||
JOptionPane.showMessageDialog(null,"恭喜以下同学被选中:\n\t\n"+messageObject.getCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.MessageType;
|
||||
import com.cfive.classroom.library.net.util.ReceiveListener;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -28,10 +29,10 @@ 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, false));
|
||||
studentNet.sendMessageThread(new MessageObject(stuNo, stuName, null, String.valueOf(sendText.getText()), null, MessageType.Chat));
|
||||
}
|
||||
else{
|
||||
JOptionPane.showMessageDialog(null,"无发送内容");
|
||||
JOptionPane.showMessageDialog(null,"无发送内容","错误!",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -39,7 +40,9 @@ public class Chat {
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
receiveText.setText("教师:\n"+messageObject.getMessage());
|
||||
if(messageObject.getMessageType()==MessageType.ChatToAll){
|
||||
receiveText.setText("教师:\n"+messageObject.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
3
Teacher/src/main/connect.properties
Normal file
3
Teacher/src/main/connect.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
#
|
||||
#Sat Jun 11 00:33:50 CST 2022
|
||||
port=8888
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.net.TeacherNet;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -22,6 +23,7 @@ public class Attendance {
|
||||
private JTable table_already;
|
||||
private JTable table_undo;
|
||||
private JLabel test;
|
||||
private TeacherNet teacherNet;
|
||||
private static final Logger LOGGER= LogManager.getLogger();
|
||||
|
||||
public Attendance() {
|
||||
@@ -52,11 +54,12 @@ public class Attendance {
|
||||
frame.setVisible(false);
|
||||
|
||||
}
|
||||
public void start(){
|
||||
public void start(TeacherNet teacherNet1){
|
||||
frame.setContentPane(attendance.rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
attendance.teacherNet=teacherNet1;
|
||||
DefaultTableModel alreadyTableModel=new DefaultTableModel(data,t1_columnTitle);
|
||||
alreadyTableModel.setColumnCount(3);
|
||||
attendance.table_already.setModel(alreadyTableModel);
|
||||
|
||||
@@ -114,7 +114,7 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="b49fe" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true">
|
||||
<component id="b49fe" class="javax.swing.JPasswordField" binding="newPw_ok">
|
||||
<constraints>
|
||||
<grid row="2" 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"/>
|
||||
@@ -122,7 +122,7 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="4d8af" class="javax.swing.JPasswordField" binding="passwordField2" default-binding="true">
|
||||
<component id="4d8af" class="javax.swing.JPasswordField" binding="newPassword">
|
||||
<constraints>
|
||||
<grid row="1" 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"/>
|
||||
|
||||
@@ -1,23 +1,48 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
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 java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ChangePassword {
|
||||
private static final ChangePassword changePassword=new ChangePassword();
|
||||
private static JFrame frame = new JFrame("修改密码");
|
||||
private JPanel rootPanel;
|
||||
private JTextField workNo_input;
|
||||
private JButton cancel;
|
||||
private JButton confirm;
|
||||
private JPasswordField passwordField1;
|
||||
private JPasswordField passwordField2;
|
||||
private JPasswordField newPw_ok;
|
||||
private JPasswordField newPassword;
|
||||
private String workNo,password1,password2;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
static JFrame frame = new JFrame("ChangePassword");
|
||||
|
||||
public ChangePassword() {
|
||||
confirm.addActionListener(e -> {
|
||||
if(check()){
|
||||
//将修改后的密码在数据表修改
|
||||
try {
|
||||
DatabaseHelper.changePasswdInTeacher(Long.valueOf(workNo_input.getText()),newPw_ok.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();
|
||||
}
|
||||
});
|
||||
@@ -45,8 +70,8 @@ public class ChangePassword {
|
||||
}
|
||||
|
||||
private boolean check() {
|
||||
password1 = String.valueOf(changePassword.passwordField1.getPassword());
|
||||
password2 = String.valueOf(changePassword.passwordField2.getPassword());
|
||||
password1 = String.valueOf(changePassword.newPw_ok.getPassword());
|
||||
password2 = String.valueOf(changePassword.newPassword.getPassword());
|
||||
if(String.valueOf(changePassword.workNo_input.getText()).equals(workNo))
|
||||
{
|
||||
if (password1.length()==0 || password2.length()==0) {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.net.TeacherNet;
|
||||
import com.cfive.classroom.library.net.util.MessageObject;
|
||||
import com.cfive.classroom.library.net.util.MessageType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -20,16 +23,18 @@ 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() {
|
||||
//限制签到码的长度
|
||||
//取消按钮的监听
|
||||
bt_cancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
//限制签到码的长度
|
||||
textField1.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
@@ -70,7 +75,15 @@ public class CheckIn {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
number=n1+n2+n3+n4;
|
||||
LOGGER.info(number);
|
||||
if(number!=null){
|
||||
LOGGER.info(number);
|
||||
teacherNet.sendAllMessage(new MessageObject(null,null,number,null,null, MessageType.CheckIn));
|
||||
JOptionPane.showMessageDialog(null,"签到码发布成功","消息",JOptionPane.INFORMATION_MESSAGE);
|
||||
frame.dispose();
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(null,"签到码不能为空","错误",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -81,11 +94,12 @@ public class CheckIn {
|
||||
frame.pack();
|
||||
frame.setVisible(false);
|
||||
}
|
||||
public void start(){
|
||||
public void start(TeacherNet teacherNet1){
|
||||
frame.setContentPane(checkIn.rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
checkIn.teacherNet=teacherNet1;
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="bae0" class="javax.swing.JButton" binding="Button1">
|
||||
<component id="bae0" class="javax.swing.JButton" binding="bt_enter">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="2" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="129" height="30"/>
|
||||
|
||||
@@ -4,87 +4,72 @@ import com.cfive.classroom.library.database.DatabaseHelper;
|
||||
import com.cfive.classroom.library.database.bean.Course;
|
||||
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
|
||||
import com.cfive.classroom.library.database.util.NoConfigException;
|
||||
import com.cfive.classroom.library.net.TeacherNet;
|
||||
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.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
public class ClassList {
|
||||
private static final ClassList classlist=new ClassList();
|
||||
private static final ClassList classList = new ClassList();
|
||||
private static JFrame frame = new JFrame("课堂互动通-教师端");
|
||||
private JPanel rootPanel1;
|
||||
private JButton Button1;
|
||||
private JButton bt_enter;
|
||||
private JComboBox comboBox;
|
||||
private JPanel selectPanel;
|
||||
private String workerNo, subName;
|
||||
private List<Course> courseList;
|
||||
private String workerNo,courseID,subName;
|
||||
private final List<Course> courseList = new ArrayList<>();
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private TeacherNet teacherNet;
|
||||
|
||||
public ClassList() {
|
||||
Button1.addActionListener(new ActionListener() {
|
||||
bt_enter.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
subName =(String) classlist.comboBox.getSelectedItem();
|
||||
//从配置文件中读取端口号并传参到主界面
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new BufferedReader(new FileReader("Teacher/src/main/connect.properties")));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
if (!Objects.equals(classList.comboBox.getSelectedItem(), "--请选择--")) { //判断是否有选择内容
|
||||
String select = classList.comboBox.getSelectedItem().toString();
|
||||
courseID = select.substring(0, select.indexOf(" "));
|
||||
subName=select.substring(select.indexOf(" ")+1);
|
||||
LOGGER.debug(courseID+" "+subName);
|
||||
Main.start(workerNo,courseID,subName);
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "请选择您想要进入的课程", "温馨提示!", JOptionPane.WARNING_MESSAGE);
|
||||
}
|
||||
LOGGER.info(properties.getProperty("port"));
|
||||
try {
|
||||
teacherNet = new TeacherNet(Integer.valueOf(properties.getProperty("port")));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
if(subName!=null){
|
||||
Main.start(classlist.workerNo,classlist.subName,teacherNet);
|
||||
}
|
||||
frame.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(classlist.rootPanel1);
|
||||
frame.setContentPane(classList.rootPanel1);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.pack();
|
||||
frame.setVisible(false);
|
||||
|
||||
}
|
||||
public void start(String workerNo){
|
||||
frame.setContentPane(classlist.rootPanel1);
|
||||
frame.setSize(600,400);
|
||||
|
||||
public void start(String workerNo) {
|
||||
frame.setContentPane(classList.rootPanel1);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
classlist.workerNo=workerNo;
|
||||
//添加下拉列表的内容:该教师所教的科目名
|
||||
classList.workerNo = workerNo;
|
||||
//添加下拉列表的内容:该教师所教的科目名以及其课程编号
|
||||
try {
|
||||
courseList=DatabaseHelper.queryCourses(Long.valueOf(classlist.workerNo));
|
||||
if(courseList!=null){
|
||||
Iterator<Course> iterator = courseList.iterator(); //使用迭代器进行遍历
|
||||
while(iterator.hasNext()){
|
||||
String subName = iterator.next().getSubject().getSubName();
|
||||
classlist.comboBox.addItem(subName);
|
||||
}
|
||||
classList.comboBox.addItem("--请选择--");
|
||||
courseList.addAll(DatabaseHelper.queryCourses(Long.parseLong(classList.workerNo)));
|
||||
for (Course course : courseList) {
|
||||
classList.comboBox.addItem(course.getCourID()+" "+course.getSubject().getSubName());
|
||||
}
|
||||
} catch (NoConfigException e) {
|
||||
throw new RuntimeException(e);
|
||||
JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("No configuration", e);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
JOptionPane.showMessageDialog(null, "数据库出错", "警告", JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("SQLException", e);
|
||||
} catch (DependenciesNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
LOGGER.error("DependenciesNotFoundException", e);
|
||||
}
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.database.DatabaseHelper;
|
||||
import com.cfive.classroom.library.database.bean.Course;
|
||||
import com.cfive.classroom.library.database.bean.Student;
|
||||
import com.cfive.classroom.library.database.bean.Subject;
|
||||
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
|
||||
import com.cfive.classroom.library.database.util.NoConfigException;
|
||||
import com.cfive.classroom.library.net.TeacherNet;
|
||||
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;
|
||||
@@ -13,14 +16,16 @@ import org.apache.logging.log4j.Logger;
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.*;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Main {
|
||||
private static final Main main=new Main();
|
||||
private static JFrame frame = new JFrame("课堂互动通");
|
||||
private static final Main main = new Main();
|
||||
private static JFrame frame = new JFrame("课堂互动通");
|
||||
private JPanel rootPanel;
|
||||
private JButton bt_checkIn;
|
||||
private JButton bt_attendance;
|
||||
@@ -30,108 +35,137 @@ public class Main {
|
||||
private JButton changePasswordButton;
|
||||
private JTextField workNo_show;
|
||||
private JTextField subName_show;
|
||||
private String workNo,subName;
|
||||
private String workNo,courseID;
|
||||
private List<Student> studentList;
|
||||
private String[] student;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private TeacherNet teacherNet;
|
||||
private final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public Main() {
|
||||
|
||||
//从配置文件中读取端口号并传参到主界面
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileReader("Teacher/src/main/connect.properties"));
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error("IOException", ex);
|
||||
}
|
||||
LOGGER.debug(properties.getProperty("port"));
|
||||
try {
|
||||
if (!properties.getProperty("port").isEmpty()) {
|
||||
teacherNet = new TeacherNet(Integer.valueOf(properties.getProperty("port")));
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
LOGGER.error("IOException", ex);
|
||||
}
|
||||
|
||||
//发送消息按钮的监听
|
||||
bt_sendMessage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SendMessage sendMessage=new SendMessage();
|
||||
SendMessage sendMessage = new SendMessage();
|
||||
sendMessage.start(teacherNet);
|
||||
}
|
||||
});
|
||||
|
||||
//发布签到按钮的监听
|
||||
bt_checkIn.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
CheckIn checkIn=new CheckIn();
|
||||
checkIn.start();
|
||||
CheckIn checkIn = new CheckIn();
|
||||
checkIn.start(teacherNet);
|
||||
}
|
||||
});
|
||||
////考勤情况按钮的监听
|
||||
|
||||
// 考勤情况按钮的监听
|
||||
bt_attendance.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Attendance attendance=new Attendance();
|
||||
attendance.start();
|
||||
Attendance attendance = new Attendance();
|
||||
attendance.start(teacherNet);
|
||||
}
|
||||
});
|
||||
////随机选人按钮的监听
|
||||
|
||||
//随机选人按钮的监听
|
||||
bt_select.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
int person;
|
||||
String count;
|
||||
String count="";
|
||||
Object[] dropList = {"提问1个同学", "提问2个同学", "提问3个同学", "提问4个同学", "提问5个同学", "提问6个同学", "提问7个同学"};
|
||||
Object selectedValue = JOptionPane.showInputDialog(null, "选择提问同学个数", "随机选人,持续工作中...",
|
||||
JOptionPane.INFORMATION_MESSAGE, null, dropList, dropList[0]); //下拉列表的内容:选择提问的人数
|
||||
while (true) {
|
||||
count = "";
|
||||
String substring = selectedValue.toString().substring(2, 3); //获取所选择的人数转化成int类型
|
||||
int i = Integer.parseInt(substring);
|
||||
String[] arr = new String[i]; //new一个该数长度的String数组
|
||||
String substring = selectedValue.toString().substring(2, 3); //获取所选择的人数转化成int类型
|
||||
int i = Integer.parseInt(substring);
|
||||
String[] arr = new String[i]; //new一个该数长度的String数组
|
||||
|
||||
try {
|
||||
studentList = DatabaseHelper.selectStudentsFromCourse(DatabaseHelper.selectFromSubject(subName).getSubID());
|
||||
if(studentList!=null){
|
||||
for (int j = 0; j < i; ) {
|
||||
//随机得到的数值
|
||||
person = (int) (Math.random() * studentList.size());
|
||||
//将该数组转化为列表,并看该列表是否包含该随机数,没有则添加进去
|
||||
if (!Arrays.asList(arr).contains(String.valueOf(person))) {
|
||||
arr[j] = String.valueOf(person);
|
||||
j++;
|
||||
}
|
||||
try {
|
||||
studentList = DatabaseHelper.selectStudentsFromCourse(Long.parseLong(courseID));
|
||||
if (!studentList.isEmpty()) { //判断是否获取到学生名单
|
||||
LOGGER.info("学生列表" + studentList);
|
||||
for (int j = 0; j < i; ) {
|
||||
//随机得到的数值
|
||||
person = (int) (Math.random() * studentList.size());
|
||||
LOGGER.info("随机值:" + person);
|
||||
//将该数组转化为列表,并看该列表是否包含该随机数,没有则添加进去(确保随机数不重复)
|
||||
if (!Arrays.asList(arr).contains(String.valueOf(person))) {
|
||||
arr[j] = String.valueOf(person);
|
||||
j++;
|
||||
}
|
||||
Iterator<Student> iterator = studentList.iterator();
|
||||
while (iterator.hasNext()){
|
||||
student=new String[studentList.size()];
|
||||
for(int k=0;k< studentList.size();k++){
|
||||
student[k]=iterator.next().getStuName();
|
||||
}
|
||||
|
||||
}
|
||||
for (int s = 0; s < arr.length; s++) { //遍历该数组并把每一个随机数所对应的人放到count中
|
||||
person = Integer.parseInt(arr[s]);
|
||||
count +=student[person];
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count);
|
||||
//将选人结果群发出去
|
||||
teacherNet.sendAllMessage(new MessageObject(null,null,null,null,count,true));
|
||||
}
|
||||
break;
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (NoConfigException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (SQLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
Iterator<Student> iterator = studentList.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
student = new String[studentList.size()];
|
||||
for (int k = 0; k < studentList.size(); k++) {
|
||||
student[k] = iterator.next().getStuName();
|
||||
}
|
||||
|
||||
}
|
||||
for (int s = 0; s < arr.length; s++) { //遍历该数组并把每一个随机数所对应的人放到count中
|
||||
person = Integer.parseInt(arr[s]);
|
||||
count += student[person];
|
||||
count+=" ";
|
||||
}
|
||||
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count);
|
||||
//将选人结果群发出去
|
||||
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, MessageType.Select));
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(null, "学生名单未导入", "错误", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
LOGGER.error("DependenciesNotFoundException", e);
|
||||
} 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
//修改密码按钮的监听
|
||||
changePasswordButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChangePassword changePassword=new ChangePassword();
|
||||
ChangePassword changePassword = new ChangePassword();
|
||||
changePassword.start(main.workNo);
|
||||
}
|
||||
});
|
||||
|
||||
//学生端举手监听
|
||||
//主界面线程监听
|
||||
teacherNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.isState()) {
|
||||
JOptionPane.showMessageDialog(null,messageObject.getStuName()+" 举手了","温馨提示!",JOptionPane.INFORMATION_MESSAGE);
|
||||
messageObject.setState(false);
|
||||
//学生端举手监听
|
||||
if (messageObject.getMessageType() == MessageType.RaiseHand) {
|
||||
JOptionPane.showMessageDialog(null, messageObject.getStuName() + " 举手了", "温馨提示!", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
//学生留言监听
|
||||
if (messageObject.getMessageType() == MessageType.Chat) {
|
||||
JOptionPane.showMessageDialog(null, messageObject.getMessage(), "学生 " + messageObject.getStuName() + " 向您留言", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -144,17 +178,17 @@ public class Main {
|
||||
frame.setVisible(false);
|
||||
}
|
||||
|
||||
public static void start(String workerNo, String subName, TeacherNet teacherNet1){
|
||||
public static void start(String workerNo,String courseID,String subName) {
|
||||
frame.setContentPane(main.rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
main.workNo=workerNo;
|
||||
main.subName=subName;
|
||||
main.teacherNet = teacherNet1;
|
||||
main.workNo = workerNo;
|
||||
main.courseID = courseID;
|
||||
//开启主界面即读取端口号
|
||||
main.workNo_show.setText(workerNo);
|
||||
main.subName_show.setText(subName);
|
||||
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="c04c0" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="5" bottom="0" right="5"/>
|
||||
<margin top="50" left="15" bottom="50" right="15"/>
|
||||
<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"/>
|
||||
</constraints>
|
||||
@@ -36,14 +36,14 @@
|
||||
</children>
|
||||
</scrollpane>
|
||||
<grid id="6683c" 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="5" right="0"/>
|
||||
<margin top="5" left="0" bottom="0" right="5"/>
|
||||
<constraints>
|
||||
<grid row="3" 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>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e278e" class="javax.swing.JButton" binding="bt_send">
|
||||
<component id="e278e" class="javax.swing.JButton" binding="bt_sendMessage">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
package com.cfive.classroom.teacher;
|
||||
|
||||
import com.cfive.classroom.library.net.TeacherNet;
|
||||
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 javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class SendMessage {
|
||||
private static final SendMessage sendMessage=new SendMessage();
|
||||
@@ -10,10 +17,46 @@ public class SendMessage {
|
||||
private static JFrame frame = new JFrame("SendMessage");
|
||||
private JPanel rootPanel;
|
||||
private JTextArea messageInput;
|
||||
private JButton bt_send;
|
||||
private JButton bt_sendMessage;
|
||||
private JTextArea messageShow;
|
||||
private TeacherNet teacherNet;
|
||||
|
||||
public SendMessage() {
|
||||
//接收学生发过来的留言
|
||||
if(teacherNet!=null){
|
||||
teacherNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if(messageObject.getMessageType()==MessageType.Chat){
|
||||
SimpleDateFormat sendTime = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
|
||||
messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(System.currentTimeMillis())+'\n'+messageObject.getMessage());
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//发送按钮的监听
|
||||
bt_sendMessage.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String messageToAll = messageInput.getText();
|
||||
if(messageToAll!=null){
|
||||
SimpleDateFormat sendTime = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
|
||||
messageShow.append("@所有人: "+sendTime.format(System.currentTimeMillis())+'\n'+messageToAll+'\n');
|
||||
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null, MessageType.ChatToAll);
|
||||
teacherNet.sendAllMessage(messageObject);
|
||||
messageInput.setText("");
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(null,"无发送内容","错误!",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(sendMessage.rootPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
@@ -40,28 +40,28 @@ public class SignIn {
|
||||
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();
|
||||
String test=sigIn.workerNo_input.getText().toString();
|
||||
classList.start(test);
|
||||
classList.start(sigIn.workerNo); //将工号传参到下一个界面
|
||||
frame.setVisible(false);
|
||||
}else {
|
||||
JOptionPane.showMessageDialog(null,"密码错误,请重新输入","错误!!",JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
} catch (NoConfigException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("No configuration", e);
|
||||
} catch (SQLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("SQLException",e);
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
LOGGER.error("DependenciesNotFoundException",e);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
LOGGER.error("NoSuchAlgorithmException",e);
|
||||
} catch (InvalidKeySpecException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
LOGGER.error("InvalidKeySpecException",e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user