comparison src/main/java/alice/test/chat/ChatWindow.java @ 601:30f2c04571c2 dispose

add chat, add Star topology to topology manager&node
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Wed, 27 Apr 2016 16:28:10 +0900
parents
children 8a9fd716c335
comparison
equal deleted inserted replaced
600:0564f38e9bfe 601:30f2c04571c2
1 package alice.test.chat;
2
3 import alice.codesegment.CodeSegment;
4 import alice.datasegment.CommandType;
5 import alice.datasegment.Receiver;
6
7 import javax.swing.*;
8 import java.awt.*;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11
12 /**
13 * Created by e125769 on 3/29/16.
14 */
15 public class ChatWindow extends CodeSegment{
16
17 public JTextArea textArea;
18 public Receiver name = ids.create(CommandType.PEEK);
19
20 public ChatWindow(){
21 name.setKey("local","userName");
22 }
23
24 @Override
25 public void run() {
26 JFrame mainFrame = new JFrame("Chat");
27 mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
28 mainFrame.setSize(300, 500);
29 mainFrame.setLocationRelativeTo(null);
30 Container contentPane = mainFrame.getContentPane();
31
32 textArea = new JTextArea(5,0);
33 JScrollPane scrollPane = new JScrollPane(textArea);
34
35 final JTextField textField = new JTextField();
36 textField.addActionListener(new ActionListener() {
37 public void actionPerformed(ActionEvent e) {
38 send("(" + name+ ") " + textField.getText() + "\n");
39 textField.setText("");
40 }
41 });
42
43 contentPane.add(scrollPane, BorderLayout.CENTER);
44 contentPane.add(textField, BorderLayout.SOUTH);
45 mainFrame.setVisible(true);
46 }
47
48 public void show(String message){
49 textArea.append(message);
50 }
51
52 public void send(String message){
53 ods.put("sendMessage", message);
54 }
55 }