mirror of
https://github.com/FatttSnake/ClassroomInteraction.git
synced 2026-04-06 06:31:26 +08:00
Init student
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.cfive.classroom.student.Center">
|
||||
<grid id="27dc6" binding="rootpanel2" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="27dc6" binding="rootpanel" layout-manager="GridLayoutManager" row-count="3" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="50" left="50" bottom="50" right="50"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="400"/>
|
||||
@@ -16,7 +16,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="1a8f9" class="javax.swing.JButton" binding="button2">
|
||||
<component id="1a8f9" class="javax.swing.JButton" binding="raiseHandButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="80" height="40"/>
|
||||
@@ -41,17 +41,10 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Microsoft YaHei" size="20" style="0"/>
|
||||
<text value="学号"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="24679" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="58188" class="javax.swing.JButton" binding="changePasswordButton">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
@@ -60,6 +53,16 @@
|
||||
<text value="修改密码"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="2c923" class="javax.swing.JTextField" binding="stuNoText">
|
||||
<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"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<editable value="false"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="9734" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
@@ -70,7 +73,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="47a94" class="javax.swing.JButton" binding="Button1">
|
||||
<component id="47a94" class="javax.swing.JButton" binding="signInButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="80" height="40"/>
|
||||
@@ -97,7 +100,7 @@
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value="聊天"/>
|
||||
<text value="留言"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
@@ -115,10 +118,11 @@
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Microsoft YaHei" size="20" style="0"/>
|
||||
<text value="课程"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="8648e" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
|
||||
<component id="8648e" class="javax.swing.JTextArea" binding="textClass">
|
||||
<constraints>
|
||||
<grid row="0" column="1" 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"/>
|
||||
@@ -126,7 +130,7 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="ebeec" class="javax.swing.JButton" binding="连接Button" default-binding="true">
|
||||
<component id="ebeec" class="javax.swing.JButton" binding="connectButton">
|
||||
<constraints>
|
||||
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
|
||||
@@ -1,61 +1,147 @@
|
||||
package com.cfive.classroom.student;
|
||||
|
||||
import com.cfive.classroom.library.database.DatabaseHelper;
|
||||
import com.cfive.classroom.library.database.util.NoConfigException;
|
||||
import com.cfive.classroom.library.net.StudentNet;
|
||||
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.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Center {
|
||||
private JButton Button1;
|
||||
private JButton button2;
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final Center center = new Center();
|
||||
private JButton signInButton;
|
||||
private JButton raiseHandButton;
|
||||
private JButton chatButton;
|
||||
private JPanel rootpanel2;
|
||||
private JTextField textField1;
|
||||
private JPanel rootpanel;
|
||||
private JButton changePasswordButton;
|
||||
private JTextArea textArea1;
|
||||
private JButton 连接Button;
|
||||
static JFrame frame = new JFrame("Center");
|
||||
private JTextArea textClass;
|
||||
private JButton connectButton;
|
||||
private JTextField stuNoText;
|
||||
private static JFrame frame = new JFrame("Center");
|
||||
private StudentNet studentNet;
|
||||
private String host;
|
||||
private int port;
|
||||
private String signInCode;
|
||||
private String stuNo;
|
||||
private String stuName;
|
||||
private MessageObject messageObject;
|
||||
|
||||
public Center() {
|
||||
|
||||
//留言
|
||||
chatButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Chat chat = new Chat();
|
||||
chat.start();
|
||||
chat.start(stuNo,stuName,studentNet);
|
||||
}
|
||||
});
|
||||
//修改密码
|
||||
changePasswordButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChangePassword changePassword = new ChangePassword();
|
||||
changePassword.start();
|
||||
frame.setVisible(false);
|
||||
changePassword.start(stuNoText.getText());
|
||||
}
|
||||
});
|
||||
Button1.addActionListener(new ActionListener() {
|
||||
//连接
|
||||
connectButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String code = JOptionPane.showInputDialog(null,"签到码:","签到",JOptionPane.PLAIN_MESSAGE);
|
||||
if (code.equals("1234")) {
|
||||
JOptionPane.showMessageDialog(null, "签到成功");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null,"签到失败");
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new BufferedReader(new FileReader("Student/src/main/connect.properties")));
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
host = properties.getProperty("host");
|
||||
port = Integer.parseInt(properties.getProperty("port"));
|
||||
try {
|
||||
studentNet = new StudentNet(host,port);
|
||||
JOptionPane.showMessageDialog(null, "连接成功");
|
||||
} catch (IOException ex) {
|
||||
JOptionPane.showMessageDialog(null,"连接失败");
|
||||
LOGGER.error("IOException",ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
//签到
|
||||
signInButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
signInCode = JOptionPane.showInputDialog(null,"签到码:","签到",JOptionPane.PLAIN_MESSAGE);
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.getCode().equals(signInCode)) {
|
||||
JOptionPane.showMessageDialog(null, "签到成功");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null,"签到失败");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//举手
|
||||
raiseHandButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
messageObject = new MessageObject(stuNo, stuName, null, null, null,true);
|
||||
studentNet.sendMessageThread(messageObject);
|
||||
JOptionPane.showMessageDialog(null,"你已经向老师举手");
|
||||
}
|
||||
});
|
||||
//随机抽人
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
if (messageObject.isState()) {
|
||||
JOptionPane.showMessageDialog(null,"恭喜以下同学被选中:\n\t\n"+messageObject.getCount());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void start(){
|
||||
frame.setContentPane(new Center().rootpanel2);
|
||||
frame.setBounds(650,300,600,400);
|
||||
|
||||
public void start(String num){
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setContentPane(center.rootpanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
frame.setVisible(true);
|
||||
center.stuNoText.setText(num);
|
||||
stuNo = String.valueOf(stuNoText.getText());
|
||||
stuName = getName();
|
||||
LOGGER.info("学号"+stuNo);
|
||||
LOGGER.info("姓名"+stuName);
|
||||
}
|
||||
//获取学生姓名
|
||||
public String getName(){
|
||||
String name = null;
|
||||
try {
|
||||
name=DatabaseHelper.selectFromStudent(Long.parseLong(stuNoText.getText())).getStuName();
|
||||
} 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);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
frame.setContentPane(new Center().rootpanel2);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(600,400);
|
||||
frame.setResizable(false);
|
||||
frame.setVisible(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="5650f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<margin top="0" left="0" bottom="0" right="50"/>
|
||||
<constraints>
|
||||
<grid row="0" 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>
|
||||
@@ -63,7 +63,7 @@
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="c0f31" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<margin top="0" left="0" bottom="0" right="20"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="120" height="74"/>
|
||||
@@ -74,25 +74,28 @@
|
||||
<children>
|
||||
<component id="27845" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" 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="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Microsoft YaHei" size="20" style="0"/>
|
||||
<text value="学号"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6c476" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Microsoft YaHei" size="20" style="0"/>
|
||||
<text value="新密码"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="11d34" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Microsoft YaHei" size="20" style="0"/>
|
||||
<text value="确认密码"/>
|
||||
</properties>
|
||||
</component>
|
||||
@@ -106,7 +109,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="4802a" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<component id="4802a" class="javax.swing.JTextField" binding="textNum">
|
||||
<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"/>
|
||||
|
||||
@@ -1,58 +1,96 @@
|
||||
package com.cfive.classroom.student;
|
||||
|
||||
import com.cfive.classroom.library.database.DatabaseHelper;
|
||||
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
|
||||
import com.cfive.classroom.library.database.util.NoConfigException;
|
||||
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.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ChangePassword {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
private static final ChangePassword changePassword = new ChangePassword();
|
||||
|
||||
private JPanel rootPanel;
|
||||
private JTextField textField1;
|
||||
private JTextField textNum;
|
||||
private JButton cancel;
|
||||
private JButton confirm;
|
||||
private JPasswordField passwordField1;
|
||||
private JPasswordField passwordField2;
|
||||
private static JFrame frame = new JFrame("修改密码");
|
||||
|
||||
static JFrame frame = new JFrame("ChangePassword");
|
||||
private String stuNo;
|
||||
|
||||
public ChangePassword() {
|
||||
confirm.addActionListener(e -> {
|
||||
if(check()){
|
||||
Center.frame.setVisible(true);
|
||||
frame.setVisible(false);
|
||||
try {
|
||||
DatabaseHelper.changePasswdInStudent(Long.parseLong(stuNo), passwordField1.getPassword().toString());
|
||||
} catch (NoConfigException ex) {
|
||||
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("No configuration", e);
|
||||
} catch (SQLException ex) {
|
||||
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
|
||||
LOGGER.error("SQLException",e);
|
||||
} catch (DependenciesNotFoundException ex) {
|
||||
LOGGER.error("DependenciesNotFoundException",e);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
LOGGER.error("NoSuchAlgorithmException",e);
|
||||
} catch (InvalidKeySpecException ex) {
|
||||
LOGGER.error("InvalidKeySpecException",e);
|
||||
}
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
cancel.addActionListener(e -> {
|
||||
Center.frame.setVisible(true);
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
frame.setContentPane(new ChangePassword().rootPanel);
|
||||
|
||||
private boolean check() {
|
||||
String password1,password2,num;
|
||||
num = String.valueOf(textNum.getText());
|
||||
|
||||
LOGGER.info("传入学号"+stuNo);
|
||||
LOGGER.info(num);
|
||||
|
||||
password1 = String.valueOf(passwordField1.getPassword());
|
||||
password2 = String.valueOf(passwordField2.getPassword());
|
||||
if(num.equals(stuNo)){
|
||||
if (password1.length()==0 || password2.length()==0) {
|
||||
JOptionPane.showMessageDialog(null,"输入的密码为空");
|
||||
return false;
|
||||
} else if (!password1.equals(password2)) {
|
||||
JOptionPane.showMessageDialog(null, "两次输入密码不同");
|
||||
return false;
|
||||
} else return true;
|
||||
}
|
||||
else {
|
||||
JOptionPane.showMessageDialog(null,"学号非本人学号");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void start(String stuNo) {
|
||||
frame.setContentPane(changePassword.rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setResizable(false);
|
||||
frame.setVisible(true);
|
||||
changePassword.stuNo = stuNo;
|
||||
LOGGER.info(changePassword.stuNo);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
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);
|
||||
frame.setBounds(650,300,600,400);
|
||||
frame.setResizable(false);
|
||||
// frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private boolean check() {
|
||||
String password1,password2;
|
||||
password1 = String.valueOf(passwordField1.getPassword());
|
||||
password2 = String.valueOf(passwordField2.getPassword());
|
||||
if (password1.length()==0 || password2.length()==0) {
|
||||
JOptionPane.showMessageDialog(null,"输入的密码为空");
|
||||
return false;
|
||||
} else if (password1.equals(password2) == false) {
|
||||
JOptionPane.showMessageDialog(null, "两次输入密码不同");
|
||||
return false;
|
||||
} else return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="70cf5" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="70cf5" 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"/>
|
||||
@@ -16,40 +16,41 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="2f7dd" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<grid id="2f7dd" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" 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>
|
||||
<component id="3ab11" class="javax.swing.JButton" binding="发送Button" default-binding="true">
|
||||
<component id="3ab11" class="javax.swing.JButton" binding="sendButton">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
|
||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="9" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="-1" height="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<text value=" 发送"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
<grid id="f0f0b" 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="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="61378" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<scrollpane id="a60c9">
|
||||
<constraints>
|
||||
<grid row="0" column="0" 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"/>
|
||||
<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="50"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8c36e" class="javax.swing.JTextArea" binding="sendText">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<editable value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</scrollpane>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
@@ -58,13 +59,17 @@
|
||||
<constraints>
|
||||
<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"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<properties>
|
||||
<background color="-1"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="13f7a" class="javax.swing.JTextArea" binding="textArea1" default-binding="true">
|
||||
<component id="13f7a" class="javax.swing.JTextArea" binding="receiveText">
|
||||
<constraints/>
|
||||
<properties>
|
||||
<background color="-1"/>
|
||||
<editable value="false"/>
|
||||
<text value=""/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
|
||||
@@ -1,23 +1,55 @@
|
||||
package com.cfive.classroom.student;
|
||||
|
||||
import com.cfive.classroom.library.net.ReceiveThread;
|
||||
import com.cfive.classroom.library.net.StudentNet;
|
||||
import com.cfive.classroom.library.net.util.MessageObject;
|
||||
import com.cfive.classroom.library.net.util.ReceiveListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Chat {
|
||||
private static final Chat chat = new Chat();
|
||||
private JPanel panel1;
|
||||
private JTextField textField1;
|
||||
private JButton 发送Button;
|
||||
private JTextArea textArea1;
|
||||
static JFrame frame = new JFrame("test");
|
||||
public void start(){
|
||||
frame.setContentPane(new Chat().panel1);
|
||||
frame.setBounds(650,300,600,400);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
private JButton sendButton;
|
||||
private JTextArea receiveText;
|
||||
private JTextArea sendText;
|
||||
private static JFrame frame = new JFrame("留言");
|
||||
private StudentNet studentNet;
|
||||
private String stuNo, stuName,host;
|
||||
private int port;
|
||||
|
||||
public Chat() {
|
||||
|
||||
//发送消息
|
||||
sendButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(String.valueOf(sendText.getText())!=null) {
|
||||
studentNet.sendMessageThread(new MessageObject(stuNo, stuName, null, String.valueOf(sendText.getText()), null, false));
|
||||
}
|
||||
else{
|
||||
JOptionPane.showMessageDialog(null,"无发送内容");
|
||||
}
|
||||
}
|
||||
});
|
||||
//接收消息
|
||||
studentNet.setOnReceiveListener(new ReceiveListener() {
|
||||
@Override
|
||||
public void onReceive(MessageObject messageObject) {
|
||||
receiveText.setText("教师:\n"+messageObject.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
public void start(String num, String name,StudentNet studentNet1) {
|
||||
frame.setContentPane(new Chat().panel1);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// frame.pack();
|
||||
frame.setVisible(false);
|
||||
frame.setSize(600, 400);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
chat.stuNo = num;
|
||||
chat.stuName = name;
|
||||
chat.studentNet = studentNet1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
<text value="学号"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="20676" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||
<component id="20676" class="javax.swing.JTextField" binding="stuNoText">
|
||||
<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"/>
|
||||
@@ -72,7 +72,7 @@
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="2a28" class="javax.swing.JLabel">
|
||||
<component id="2a28" class="javax.swing.JLabel" binding="password">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
@@ -81,7 +81,7 @@
|
||||
<text value="密码"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="59402" class="javax.swing.JPasswordField" binding="passwordField1" default-binding="true">
|
||||
<component id="59402" class="javax.swing.JPasswordField" binding="passwordText">
|
||||
<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"/>
|
||||
|
||||
@@ -1,47 +1,78 @@
|
||||
package com.cfive.classroom.student;
|
||||
|
||||
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.formdev.flatlaf.FlatLightLaf;
|
||||
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.WindowEvent;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MainWindow{
|
||||
|
||||
private static final MainWindow mainWindow = new MainWindow();
|
||||
private JPanel rootPanel;
|
||||
private JLabel title;
|
||||
private JTextField textField1;
|
||||
private JPasswordField passwordField1;
|
||||
private JTextField stuNoText;
|
||||
private JPasswordField passwordText;
|
||||
private JButton login;
|
||||
static JFrame frame = new JFrame("学生登录界面");
|
||||
private JLabel password;
|
||||
private static JFrame frame = new JFrame("学生登录界面");
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
public MainWindow() {
|
||||
//登录按钮
|
||||
login.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if(check()){
|
||||
Center center = new Center();
|
||||
center.start();
|
||||
frame.setVisible(false);
|
||||
center.start(String.valueOf(stuNoText.getText()));
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public boolean check(){
|
||||
String password = new String(passwordField1.getPassword());
|
||||
if (textField1.getText() == null || password.length() == 0) {
|
||||
String stuPassword = new String(passwordText.getPassword());
|
||||
String stuNo = new String(stuNoText.getText());
|
||||
LOGGER.info(Long.valueOf(stuNo));
|
||||
//判断密码
|
||||
if (stuNo.length() == 0 || stuPassword.length() == 0) {
|
||||
JOptionPane.showMessageDialog(null, "账号密码不能为空");
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
boolean checkPassword=false;
|
||||
try {
|
||||
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) {
|
||||
|
||||
frame.setContentPane(new MainWindow().rootPanel);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// frame.pack();
|
||||
frame.setBounds(650,300,600,400);
|
||||
FlatLightLaf.setup();
|
||||
frame.setContentPane(mainWindow.rootPanel);
|
||||
frame.setSize(600,400);
|
||||
frame.setTitle("登录");
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
frame.setResizable(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user