TeacherUI reModify

This commit is contained in:
cccccyb
2022-06-10 14:07:17 +08:00
parent a067cab066
commit 149e38046a
12 changed files with 263 additions and 104 deletions

View File

@@ -45,7 +45,8 @@ public class Attendance {
public static void main(String[] args) {
frame.setContentPane(attendance.rootPanel);
frame.setBounds(600,400,600,400);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(false);
@@ -53,7 +54,8 @@ public class Attendance {
}
public void start(){
frame.setContentPane(attendance.rootPanel);
frame.setBounds(600,400,600,400);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
DefaultTableModel alreadyTableModel=new DefaultTableModel(data,t1_columnTitle);
alreadyTableModel.setColumnCount(3);

View File

@@ -106,7 +106,7 @@
<properties/>
<border type="none"/>
<children>
<component id="4802a" class="javax.swing.JTextField" binding="workNo">
<component id="4802a" class="javax.swing.JTextField" binding="workNo_input">
<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">
<preferred-size width="150" height="-1"/>

View File

@@ -3,12 +3,14 @@ package com.cfive.classroom.teacher;
import javax.swing.*;
public class ChangePassword {
private static final ChangePassword changePassword=new ChangePassword();
private JPanel rootPanel;
private JTextField workNo;
private JTextField workNo_input;
private JButton cancel;
private JButton confirm;
private JPasswordField passwordField1;
private JPasswordField passwordField2;
private String workNo,password1,password2;
static JFrame frame = new JFrame("ChangePassword");
@@ -26,31 +28,38 @@ public class ChangePassword {
public static void main(String[] args) {
frame.setContentPane(new ChangePassword().rootPanel);
frame.setContentPane(changePassword.rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400);
frame.setVisible(false);
}
public void start() {
frame.setContentPane(new ChangePassword().rootPanel);
public void start(String workNo) {
frame.setContentPane(changePassword.rootPanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
// frame.pack();
changePassword.workNo=workNo;
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
private boolean check() {
String password1,password2;
password1 = String.valueOf(passwordField1.getPassword());
password2 = String.valueOf(passwordField2.getPassword());
password1 = String.valueOf(changePassword.passwordField1.getPassword());
password2 = String.valueOf(changePassword.passwordField2.getPassword());
if(String.valueOf(changePassword.workNo_input.getText()).equals(workNo))
{
if (password1.length()==0 || password2.length()==0) {
JOptionPane.showMessageDialog(null,"输入的密码为空");
return false;
} else if (password1.equals(password2) == false) {
} else if (!password1.equals(password2)) {
JOptionPane.showMessageDialog(null, "两次输入密码不同");
return false;
} else return true;
}else {
JOptionPane.showMessageDialog(null, "请输入正确的工号");
return false;
}
}
}

View File

@@ -83,9 +83,10 @@ public class CheckIn {
}
public void start(){
frame.setContentPane(checkIn.rootPanel);
frame.setBounds(600,400,600,400);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}

View File

@@ -32,7 +32,7 @@
</constraints>
<properties>
<font name="Microsoft YaHei" size="28" style="1"/>
<text value="选择您所要进入的班级"/>
<text value="选择您所要进入的课程"/>
</properties>
</component>
<vspacer id="3777c">

View File

@@ -1,9 +1,23 @@
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.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.awt.event.ItemListener;
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;
public class ClassList {
private static final ClassList classlist=new ClassList();
@@ -12,13 +26,31 @@ public class ClassList {
private JButton Button1;
private JComboBox comboBox;
private JPanel selectPanel;
private String workerNo,className;
private String workerNo, subName;
private List<Course> courseList;
private static final Logger LOGGER = LogManager.getLogger();
private TeacherNet teacherNet;
public ClassList() {
Button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
className=(String) classlist.comboBox.getSelectedItem();
Main.start(classlist.workerNo,classlist.className);
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);
}
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);
}
});
@@ -37,11 +69,24 @@ public class ClassList {
frame.setLocationRelativeTo(null);
frame.setResizable(false);
classlist.workerNo=workerNo;
classlist.comboBox.addItem("20软工3班");
classlist.comboBox.addItem("20软工4班");
classlist.comboBox.addItem("20软工5班");
classlist.comboBox.addItem("20软工6班");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//添加下拉列表的内容:该教师所教的科目名
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);
}
}
} catch (NoConfigException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (DependenciesNotFoundException e) {
throw new RuntimeException(e);
}
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}

View File

@@ -24,7 +24,7 @@
<properties/>
<border type="none"/>
<children>
<component id="c9e8c" class="javax.swing.JTextField" binding="className">
<component id="c9e8c" class="javax.swing.JTextField" binding="subName_show">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="9" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
@@ -41,7 +41,7 @@
</constraints>
<properties>
<font name="Microsoft YaHei" size="24" style="1"/>
<text value="班级"/>
<text value="课程"/>
</properties>
</component>
<hspacer id="41901">
@@ -115,7 +115,7 @@
<properties/>
<border type="none"/>
<children>
<component id="2d479" class="javax.swing.JTextField" binding="workNo">
<component id="2d479" class="javax.swing.JTextField" binding="workNo_show">
<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"/>

View File

@@ -1,9 +1,22 @@
package com.cfive.classroom.teacher;
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.cfive.classroom.library.net.TeacherNet;
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 java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class Main {
private static final Main main=new Main();
@@ -15,17 +28,24 @@ public class Main {
private JButton bt_sendMessage;
private JButton changePasswordButton;
private JTextField workNo;
private JTextField className;
private JTextField workNo_show;
private JTextField subName_show;
private String workNo,subName;
private List<Student> studentList;
private String[] student;
private static final Logger LOGGER = LogManager.getLogger();
private TeacherNet teacherNet;
public Main() {
//发送消息按钮的监听
bt_sendMessage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
SendMessage sendMessage=new SendMessage();
sendMessage.start();
sendMessage.start(teacherNet);
}
});
//发布签到按钮的监听
bt_checkIn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -33,6 +53,7 @@ public class Main {
checkIn.start();
}
});
////考勤情况按钮的监听
bt_attendance.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -40,43 +61,78 @@ public class Main {
attendance.start();
}
});
////随机选人按钮的监听
bt_select.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int person;
String count;
Object[] possibleValues = {"提问1个同学", "提问2个同学", "提问3个同学", "提问4个同学", "提问5个同学", "提问6个同学", "提问7个同学"};
Object[] dropList = {"提问1个同学", "提问2个同学", "提问3个同学", "提问4个同学", "提问5个同学", "提问6个同学", "提问7个同学"};
Object selectedValue = JOptionPane.showInputDialog(null, "选择提问同学个数", "随机选人,持续工作中...",
JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]);
JOptionPane.INFORMATION_MESSAGE, null, dropList, dropList[0]); //下拉列表的内容:选择提问的人数
while (true) {
count = "";
String substring = selectedValue.toString().substring(2, 3);
String substring = selectedValue.toString().substring(2, 3); //获取所选择的人数转化成int类型
int i = Integer.parseInt(substring);
String[] arr = new String[i];
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() * 10);
//遍历数组对
person = (int) (Math.random() * studentList.size());
//将该数组转化为列表,并看该列表是否包含该随机数,没有则添加进去
if (!Arrays.asList(arr).contains(String.valueOf(person))) {
arr[j] = String.valueOf(person);
j++;
}
}
String[] arr2 = {"小白 ", "小红 ", "小黑 ", "小绿 ", "小宗 ", "小橙 ", "小黄 ", "小青 ", "小蓝 ", "小紫 ", };
for (int s = 0; s < arr.length; s++) {
person = Integer.parseInt(arr[s]);
count += arr2[person];
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));
}
JOptionPane.showMessageDialog(null, "恭喜以下同学,获得了本次回答问题的机会\n\t\n" + count);
break;
} catch (DependenciesNotFoundException ex) {
throw new RuntimeException(ex);
} catch (NoConfigException ex) {
throw new RuntimeException(ex);
} catch (SQLException ex) {
throw new RuntimeException(ex);
}
}
}
});
//修改密码按钮的监听
changePasswordButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ChangePassword changePassword=new ChangePassword();
changePassword.start();
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);
}
}
});
}
@@ -88,13 +144,17 @@ public class Main {
frame.setVisible(false);
}
public static void start(String workerNo,String className){
public static void start(String workerNo, String subName, TeacherNet teacherNet1){
frame.setContentPane(main.rootPanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
main.workNo.setText(workerNo);
main.className.setText(className);
main.workNo=workerNo;
main.subName=subName;
main.teacherNet = teacherNet1;
//开启主界面即读取端口号
main.workNo_show.setText(workerNo);
main.subName_show.setText(subName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

View File

@@ -16,35 +16,22 @@
<properties/>
<border type="none"/>
<children>
<component id="aa5a2" class="javax.swing.JTextPane" binding="textPane1" default-binding="true">
<constraints>
<grid row="0" column="0" 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"/>
</grid>
</constraints>
<properties>
<editable value="false"/>
</properties>
</component>
<grid id="855b2" 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>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
<scrollpane id="ac4d">
<constraints>
<grid row="2" 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">
<preferred-size width="-1" height="120"/>
</grid>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="7754d" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
<component id="9bbcf" class="javax.swing.JTextArea" binding="messageShow">
<constraints/>
<properties/>
<properties>
<background color="-1"/>
<editable value="false"/>
<foreground color="-16777216"/>
</properties>
</component>
</children>
</scrollpane>
@@ -58,7 +45,7 @@
<children>
<component id="e278e" class="javax.swing.JButton" binding="bt_send">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" 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="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="发送"/>
@@ -66,6 +53,28 @@
</component>
</children>
</grid>
<scrollpane id="d088a">
<constraints>
<grid row="2" 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>
<properties/>
<border type="none"/>
<children>
<component id="faa35" class="javax.swing.JTextArea" binding="messageInput">
<constraints/>
<properties/>
</component>
</children>
</scrollpane>
<grid id="855b2" 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>
<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"/>
</constraints>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>

View File

@@ -1,5 +1,7 @@
package com.cfive.classroom.teacher;
import com.cfive.classroom.library.net.TeacherNet;
import javax.swing.*;
public class SendMessage {
@@ -7,9 +9,10 @@ public class SendMessage {
private static JFrame frame = new JFrame("SendMessage");
private JPanel rootPanel;
private JTextPane textPane1;
private JTextArea textArea1;
private JTextArea messageInput;
private JButton bt_send;
private JTextArea messageShow;
private TeacherNet teacherNet;
public static void main(String[] args) {
frame.setContentPane(sendMessage.rootPanel);
@@ -18,11 +21,13 @@ public class SendMessage {
frame.setVisible(false);
}
public void start(){
public void start(TeacherNet teacherNet1){
frame.setContentPane(sendMessage.rootPanel);
frame.setBounds(600,400,600,400);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
sendMessage.teacherNet = teacherNet1;
}
}

View File

@@ -55,7 +55,7 @@
<text value="工号"/>
</properties>
</component>
<component id="64a15" class="javax.swing.JTextField" binding="workerNo">
<component id="64a15" class="javax.swing.JTextField" binding="workerNo_input">
<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"/>
@@ -84,7 +84,7 @@
<text value="密码"/>
</properties>
</component>
<component id="5357c" class="javax.swing.JPasswordField" binding="password">
<component id="5357c" class="javax.swing.JPasswordField" binding="password_input">
<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"/>

View File

@@ -1,21 +1,30 @@
package com.cfive.classroom.teacher;
import com.formdev.flatlaf.FlatDarculaLaf;
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.formdev.flatlaf.FlatLightLaf;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.sql.SQLException;
import java.util.List;
public class SignIn {
private static final SignIn sigIn = new SignIn();
private static final JFrame frame = new JFrame("教师端");;
private JPanel rootJPanel;
private JButton login_Button;
private JTextField workerNo;
private JPasswordField password;
private JTextField workerNo_input;
private JPasswordField password_input;
private String workerNo,password;
private static final Logger LOGGER = LogManager.getLogger();
public static void main(String[] args) {
FlatLightLaf.setup();
@@ -26,14 +35,33 @@ public class SignIn {
sigIn.login_Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(!sigIn.workerNo.getText().isEmpty()&&!sigIn.password.getText().isEmpty()){
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();
String test=sigIn.workerNo.getText().toString();
String test=sigIn.workerNo_input.getText().toString();
classList.start(test);
frame.setVisible(false);
}else{
}else {
JOptionPane.showMessageDialog(null,"密码错误,请重新输入","错误!!",JOptionPane.ERROR_MESSAGE);
}
} catch (NoConfigException ex) {
throw new RuntimeException(ex);
} catch (SQLException ex) {
throw new RuntimeException(ex);
} catch (DependenciesNotFoundException ex) {
throw new RuntimeException(ex);
} catch (NoSuchAlgorithmException ex) {
throw new RuntimeException(ex);
} catch (InvalidKeySpecException ex) {
throw new RuntimeException(ex);
}
JOptionPane.showMessageDialog(null,"用户名和密码不能为空","提示!!",JOptionPane.ERROR_MESSAGE);
}
}