mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 02:21:26 +08:00
Init student's Center,Chat,MainWindow
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user