-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChatApp.java
92 lines (90 loc) · 2.39 KB
/
ChatApp.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
import org.jibble.pircbot.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* This is our GUI class
*/
public class ChatApp implements ActionListener {
private JTextArea textArea;
private JTextField textData;
private JFrame frame;
private IrcBot bot;
public ChatApp() {
textArea = new JTextArea();
textArea.setEditable(false);
textData = new JTextField();
textData.addActionListener(this);
frame = new JFrame("LightIRC Client");
//Set name of IRC Client frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
frame.add(textData, BorderLayout.SOUTH);
frame.setMinimumSize(new Dimension(485, 300));
frame.setLocationRelativeTo(null);
textData.grabFocus();
}
public void listen(IrcBot bot)
{
this.bot = bot;
}
public void actionPerformed(ActionEvent e)
{
String data = textData.getText() + "\n";
textArea.append(bot.getNick() + " " + data);
textData.setText("");
if (!bot.commands(data)) {
bot.sendMessage(bot.getNick(), data);
}
}
public void listUsers(User array[])
{
final User users[] = array;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
for (User u : users)
{
textArea.append(u.toString() + "\n");
}
}
}
);
}
public void appendTopic(String topic)
{
final String top = topic;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
textArea.append(top + "\n");
}
}
);
}
public void appendMessage(String message)
{
final String msg = message;
EventQueue.invokeLater(new Runnable()
{
public void run()
{
textArea.append(msg + "\n");
}
}
);
}
public void setDisplay(boolean b)
{
EventQueue.invokeLater(new Runnable()
{
public void run()
{
frame.setVisible(true);
}
}
);
}
}