From f376c08dcf65c0eb4197080b6c2a08d0e5c67220 Mon Sep 17 00:00:00 2001 From: GGB <1223416496@qq.com> Date: Sun, 12 Jun 2022 19:35:43 +0800 Subject: [PATCH] Init student's Center,Chat,MainWindow --- .../com/cfive/classroom/student/Center.java | 23 ++----- .../com/cfive/classroom/student/Chat.java | 4 +- .../cfive/classroom/student/MainWindow.java | 66 +++++++++---------- 3 files changed, 41 insertions(+), 52 deletions(-) diff --git a/Student/src/main/java/com/cfive/classroom/student/Center.java b/Student/src/main/java/com/cfive/classroom/student/Center.java index ef81d0a..650d356 100644 --- a/Student/src/main/java/com/cfive/classroom/student/Center.java +++ b/Student/src/main/java/com/cfive/classroom/student/Center.java @@ -82,14 +82,19 @@ public class Center { try { studentNet = new StudentNet(host,port); JOptionPane.showMessageDialog(null, "连接成功"); - //签到 + studentNet.setOnReceiveListener(new ReceiveListener() { @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()); + } } }); @@ -106,7 +111,6 @@ public class Center { raiseHandButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - LOGGER.info(stuNo+stuName); messageObject = new MessageObject(stuNo, stuName, null, null, null, null,null,MessageType.RaiseHand); studentNet.sendMessage(messageObject); @@ -114,17 +118,7 @@ public class Center { JOptionPane.showMessageDialog(null,"你已经向老师举手"); } }); - //随机抽人 - if (studentNet != null) { - studentNet.setOnReceiveListener(new ReceiveListener() { - @Override - public void onReceive(MessageObject messageObject) { - if (messageObject.getMessageType()==MessageType.Select) { - JOptionPane.showMessageDialog(null,"恭喜以下同学被选中:\n\t\n"+messageObject.getCount()); - } - } - }); - } + //签到 signInButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -177,7 +171,4 @@ public class Center { } return name; } - - - } diff --git a/Student/src/main/java/com/cfive/classroom/student/Chat.java b/Student/src/main/java/com/cfive/classroom/student/Chat.java index 9378f68..b931c41 100644 --- a/Student/src/main/java/com/cfive/classroom/student/Chat.java +++ b/Student/src/main/java/com/cfive/classroom/student/Chat.java @@ -30,8 +30,8 @@ public class Chat { String sendMessage = sendText.getText(); if(sendMessage!=null) { LOGGER.info(stuNo+stuName); - receiveText.append("我:"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+sendMessage+"\n"); - studentNet.sendMessage(new MessageObject(stuNo, stuName, null,stuName+":"+sendText.getText() ,null,null,LocalDateTime.now(),MessageType.Chat)); + receiveText.append("我:"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+"\n"+sendMessage+"\n"); + studentNet.sendMessage(new MessageObject(stuNo, stuName, null,sendText.getText() ,null,null,LocalDateTime.now(),MessageType.Chat)); sendText.setText(""); } else{ diff --git a/Student/src/main/java/com/cfive/classroom/student/MainWindow.java b/Student/src/main/java/com/cfive/classroom/student/MainWindow.java index 0c89bf0..c2e6fe9 100644 --- a/Student/src/main/java/com/cfive/classroom/student/MainWindow.java +++ b/Student/src/main/java/com/cfive/classroom/student/MainWindow.java @@ -37,10 +37,7 @@ public class MainWindow{ center.start(); frame.dispose(); } - else { - JOptionPane.showMessageDialog(null,"密码错误"); - passwordText.setText(""); - } + } } @Override @@ -49,15 +46,20 @@ public class MainWindow{ login.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if(check()){ - Center center = new Center(stuNoText.getText()); - center.start(); - frame.dispose(); - } - else { - JOptionPane.showMessageDialog(null,"密码错误"); - passwordText.setText(""); + if (String.valueOf((stuNoText.getText())).length() == 0 || String.valueOf(passwordText.getPassword()).length() == 0) { + JOptionPane.showMessageDialog(null, "账号密码不能为空"); + } else { + if(check()){ + Center center = new Center(stuNoText.getText()); + center.start(); + frame.dispose(); + } + else { + JOptionPane.showMessageDialog(null,"密码错误"); + passwordText.setText(""); + } } + } }); } @@ -67,30 +69,26 @@ public class MainWindow{ LOGGER.info(Long.valueOf(stuNo)); LOGGER.info(stuPassword); //判断密码 - if (stuNo.length() == 0 || stuPassword.length() == 0) { - JOptionPane.showMessageDialog(null, "账号密码不能为空"); - return false; - } else { - boolean checkPassword = false; - try { - 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); - } 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; + boolean checkPassword = false; + try { + 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); + } 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) { FlatLightLaf.setup(); frame.setContentPane(mainWindow.rootPanel);