Init student's Center,Chat,MainWindow

This commit is contained in:
GGB
2022-06-12 19:35:43 +08:00
parent 205c639d41
commit f376c08dcf
3 changed files with 41 additions and 52 deletions

View File

@@ -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;
}
}

View File

@@ -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{

View File

@@ -37,10 +37,7 @@ public class MainWindow{
center.start();
frame.dispose();
}
else {
JOptionPane.showMessageDialog(null,"密码错误");
passwordText.setText("");
}
}
}
@Override
@@ -49,6 +46,9 @@ public class MainWindow{
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
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();
@@ -59,6 +59,8 @@ public class MainWindow{
passwordText.setText("");
}
}
}
});
}
public boolean check(){
@@ -67,10 +69,6 @@ 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));
@@ -90,7 +88,7 @@ public class MainWindow{
}
return checkPassword;
}
}
public static void main(String[] args) {
FlatLightLaf.setup();
frame.setContentPane(mainWindow.rootPanel);