-
Notifications
You must be signed in to change notification settings - Fork 0
/
Irc.java
97 lines (76 loc) · 2.01 KB
/
Irc.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import java.awt.*;
import java.awt.event.*;
public class Irc extends Frame {
public TextArea text;
public TextField data;
public Button read_button;
public Button write_button;
SharedObject sentence;
static String myName;
public static void main(String argv[]) {
if (argv.length != 1) {
System.out.println("java Irc <name>");
return;
}
myName = argv[0];
// initialisation (attendre l'ensemble des sites participants)
Client.init(myName);
// créer et diffuser un nouvel objet partagé
SharedObject s = Client.publish("IRC", new String(""), false);
// créer l'IHM
new Irc(s);
}
public Irc(SharedObject s) {
setLayout(new FlowLayout());
setTitle(myName);
text = new TextArea(10, 60);
text.setEditable(false);
text.setForeground(Color.red);
add(text);
data = new TextField(60);
add(data);
write_button = new Button("write");
write_button.addActionListener(new writeListener(this));
add(write_button);
read_button = new Button("read");
read_button.addActionListener(new readListener(this));
add(read_button);
setSize(530, 270);
text.setBackground(Color.black);
show();
sentence = s;
/*try {
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
sentence.write(myName + " : Concurrent access");*/
}
}
class readListener implements ActionListener {
Irc irc;
public readListener(Irc i) {
irc = i;
}
public void actionPerformed(ActionEvent e) {
irc.read_button.setForeground(Color.lightGray); // pour le feedback...
// display the read value
irc.text.append(((String) irc.sentence.read()) + "\n");
irc.read_button.setForeground(Color.black);
}
}
class writeListener implements ActionListener {
Irc irc;
String s;
public writeListener(Irc i) {
irc = i;
}
public void actionPerformed(ActionEvent e) {
// write the object
s = "[" + Irc.myName + "]: " + irc.data.getText();
irc.data.setText(s);// pour le feedback...
irc.sentence.write(s);
// reset text input field
irc.data.setText("");
}
}