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