mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 00:41:26 +08:00
Init Center,Chat,CheckIn,dataSources,MainWindow,PoolHelper,SendMessage
This commit is contained in:
7
.idea/dataSources.xml
generated
7
.idea/dataSources.xml
generated
@@ -8,5 +8,12 @@
|
|||||||
<jdbc-url>jdbc:mysql://10.14.0.7:3306/class</jdbc-url>
|
<jdbc-url>jdbc:mysql://10.14.0.7:3306/class</jdbc-url>
|
||||||
<working-dir>$ProjectFileDir$</working-dir>
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
</data-source>
|
</data-source>
|
||||||
|
<data-source source="LOCAL" name="class@0.tcp.jp.ngrok.io" uuid="c575a4fb-f9e1-448c-9434-8ae2fb826731">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://0.tcp.jp.ngrok.io:10088/class</jdbc-url>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -28,6 +28,7 @@ public class PoolHelper {
|
|||||||
config.setJdbcUrl(JDBC_URL);
|
config.setJdbcUrl(JDBC_URL);
|
||||||
config.setUsername(JDBC_USERNAME);
|
config.setUsername(JDBC_USERNAME);
|
||||||
config.setPassword(JDBC_PASSWORD);
|
config.setPassword(JDBC_PASSWORD);
|
||||||
|
config.setInitializationFailTimeout(30000);
|
||||||
config.addDataSourceProperty("cachePrepStmts", CACHE_PREP_STMTS);
|
config.addDataSourceProperty("cachePrepStmts", CACHE_PREP_STMTS);
|
||||||
config.addDataSourceProperty("prepStmtCacheSize", PREP_STMT_CACHE_SIZE);
|
config.addDataSourceProperty("prepStmtCacheSize", PREP_STMT_CACHE_SIZE);
|
||||||
config.addDataSourceProperty("maximumPoolSize", MAXIMUM_POOL_SIZE);
|
config.addDataSourceProperty("maximumPoolSize", MAXIMUM_POOL_SIZE);
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class Center {
|
|||||||
private JTextField stuNoText;
|
private JTextField stuNoText;
|
||||||
private JTextField stuNameText;
|
private JTextField stuNameText;
|
||||||
private JButton signInButton;
|
private JButton signInButton;
|
||||||
private static JFrame frame = new JFrame("Center");
|
private static JFrame frame = new JFrame("课堂互动通");
|
||||||
private StudentNet studentNet;
|
private StudentNet studentNet;
|
||||||
private String host;
|
private String host;
|
||||||
private int port;
|
private int port;
|
||||||
@@ -57,7 +57,6 @@ public class Center {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
LOGGER.info("chatButton.studentNet"+studentNet);
|
LOGGER.info("chatButton.studentNet"+studentNet);
|
||||||
|
|
||||||
if (studentNet != null) {
|
if (studentNet != null) {
|
||||||
if (flag == false) {
|
if (flag == false) {
|
||||||
chat = new Chat(studentNet,stuNo,stuName,chatReceiveListener);
|
chat = new Chat(studentNet,stuNo,stuName,chatReceiveListener);
|
||||||
@@ -135,29 +134,37 @@ public class Center {
|
|||||||
raiseHandButton.addActionListener(new ActionListener() {
|
raiseHandButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (studentNet != null) {
|
||||||
LOGGER.info(stuNo+stuName);
|
LOGGER.info(stuNo+stuName);
|
||||||
messageObject = new MessageObject(stuNo, stuName, null, null, null, null,null,MessageType.RaiseHand);
|
messageObject = new MessageObject(stuNo, stuName, null, null, null, null,null,MessageType.RaiseHand);
|
||||||
studentNet.sendMessage(messageObject);
|
studentNet.sendMessage(messageObject);
|
||||||
LOGGER.info(messageObject.getStuNo()+messageObject.getStuName());
|
LOGGER.info(messageObject.getStuNo()+messageObject.getStuName());
|
||||||
JOptionPane.showMessageDialog(null,"你已经向老师举手");
|
JOptionPane.showMessageDialog(null,"你已经向老师举手");
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null,"没有连接至教师");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//签到
|
//签到
|
||||||
signInButton.addActionListener(new ActionListener() {
|
signInButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (studentNet != null) {
|
||||||
if (getSignInCode != null) {
|
if (getSignInCode != null) {
|
||||||
signInCode = JOptionPane.showInputDialog(null, "签到码:", "签到", JOptionPane.PLAIN_MESSAGE);
|
signInCode = JOptionPane.showInputDialog(null, "签到码:", "签到", JOptionPane.PLAIN_MESSAGE);
|
||||||
LOGGER.info(getSignInCode);
|
LOGGER.info(getSignInCode);
|
||||||
if (getSignInCode.equals(signInCode)) {
|
if (getSignInCode.equals(signInCode)) {
|
||||||
studentNet.sendMessage(new MessageObject(stuNo, stuName, null, null, null, AttStatus.signed, LocalDateTime.now(), MessageType.CheckIn));
|
studentNet.sendMessage(new MessageObject(stuNo, stuName, null, null, null, AttStatus.signed, LocalDateTime.now(), MessageType.CheckIn));
|
||||||
LOGGER.info(stuNo+""+stuName);
|
LOGGER.info(stuNo + "" + stuName);
|
||||||
JOptionPane.showMessageDialog(null, "签到成功");
|
JOptionPane.showMessageDialog(null, "签到成功");
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null, "签到失败");
|
JOptionPane.showMessageDialog(null, "签到失败");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null,"无签到码");
|
JOptionPane.showMessageDialog(null, "无签到码");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(null,"没有连接至教师");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -173,15 +180,6 @@ public class Center {
|
|||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.setContentPane(center.rootpanel);
|
|
||||||
frame.setSize(600,400);
|
|
||||||
frame.setLocationRelativeTo(null);
|
|
||||||
frame.setResizable(false);
|
|
||||||
frame.setVisible(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
//获取学生姓名
|
//获取学生姓名
|
||||||
public String getName(String stuNo){
|
public String getName(String stuNo){
|
||||||
String name = null;
|
String name = null;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class Chat {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String sendMessage = sendText.getText();
|
String sendMessage = sendText.getText();
|
||||||
if(sendMessage!=null) {
|
if(sendMessage.length()!=0) {
|
||||||
LOGGER.info(stuNo+stuName);
|
LOGGER.info(stuNo+stuName);
|
||||||
receiveText.append("我:"+LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+"\n"+sendMessage+"\n");
|
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));
|
studentNet.sendMessage(new MessageObject(stuNo, stuName, null,sendText.getText() ,null,null,LocalDateTime.now(),MessageType.Chat));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ public class MainWindow{
|
|||||||
private JLabel password;
|
private JLabel password;
|
||||||
private static JFrame frame = new JFrame("学生登录界面");
|
private static JFrame frame = new JFrame("学生登录界面");
|
||||||
private static final Logger LOGGER = LogManager.getLogger();
|
private static final Logger LOGGER = LogManager.getLogger();
|
||||||
|
private boolean isConnectedToDatabase = false;
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
//登录按钮
|
//登录按钮
|
||||||
passwordText.addKeyListener(new KeyListener() {
|
passwordText.addKeyListener(new KeyListener() {
|
||||||
@@ -73,6 +74,7 @@ public class MainWindow{
|
|||||||
try {
|
try {
|
||||||
LOGGER.info(DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword));
|
LOGGER.info(DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword));
|
||||||
checkPassword = DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword);
|
checkPassword = DatabaseHelper.checkPasswdInStudent(Long.parseLong(stuNo), stuPassword);
|
||||||
|
isConnectedToDatabase = true;
|
||||||
} catch (NoConfigException e) {
|
} catch (NoConfigException e) {
|
||||||
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
|
||||||
LOGGER.error("No configuration", e);
|
LOGGER.error("No configuration", e);
|
||||||
@@ -85,6 +87,11 @@ public class MainWindow{
|
|||||||
LOGGER.error("NoSuchAlgorithmException",e);
|
LOGGER.error("NoSuchAlgorithmException",e);
|
||||||
} catch (InvalidKeySpecException e) {
|
} catch (InvalidKeySpecException e) {
|
||||||
LOGGER.error("InvalidKeySpecException",e);
|
LOGGER.error("InvalidKeySpecException",e);
|
||||||
|
}finally {
|
||||||
|
if (!isConnectedToDatabase) {
|
||||||
|
JOptionPane.showMessageDialog(null, "无法连接到数据库", "错误", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
isConnectedToDatabase = false;
|
||||||
}
|
}
|
||||||
return checkPassword;
|
return checkPassword;
|
||||||
}
|
}
|
||||||
@@ -93,7 +100,6 @@ public class MainWindow{
|
|||||||
FlatLightLaf.setup();
|
FlatLightLaf.setup();
|
||||||
frame.setContentPane(mainWindow.rootPanel);
|
frame.setContentPane(mainWindow.rootPanel);
|
||||||
frame.setSize(600,400);
|
frame.setSize(600,400);
|
||||||
frame.setTitle("登录");
|
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
frame.setResizable(false);
|
frame.setResizable(false);
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ public class CheckIn {
|
|||||||
if(e.getKeyChar()==KeyEvent.VK_ENTER){
|
if(e.getKeyChar()==KeyEvent.VK_ENTER){
|
||||||
//获取签到码广播出去
|
//获取签到码广播出去
|
||||||
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
||||||
if (number != null) {
|
LOGGER.info(number.length());
|
||||||
|
LOGGER.info(number);
|
||||||
|
if (number .length() == 4) {
|
||||||
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
||||||
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
||||||
frame.setVisible(false);
|
frame.setVisible(false);
|
||||||
@@ -97,7 +99,9 @@ public class CheckIn {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
|
||||||
if (number != null) {
|
LOGGER.info(number.length());
|
||||||
|
LOGGER.info(number);
|
||||||
|
if (number .length() == 4) {
|
||||||
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
|
||||||
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
|
||||||
frame.setVisible(false);
|
frame.setVisible(false);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class SendMessage {
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
String messageToAll = messageInput.getText();
|
String messageToAll = messageInput.getText();
|
||||||
if(messageToAll!=null){
|
if(messageToAll.length()!=0){
|
||||||
LocalDateTime sendTime = LocalDateTime.now();
|
LocalDateTime sendTime = LocalDateTime.now();
|
||||||
messageShow.append("@所有人: "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageToAll+'\n');
|
messageShow.append("@所有人: "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageToAll+'\n');
|
||||||
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null,null,null,MessageType.ChatToAll);
|
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null,null,null,MessageType.ChatToAll);
|
||||||
|
|||||||
Reference in New Issue
Block a user