-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextArea.java
More file actions
49 lines (40 loc) · 1.19 KB
/
TextArea.java
File metadata and controls
49 lines (40 loc) · 1.19 KB
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
package gui;
/**
* RUN:
* javac gui/TextArea.java && java gui.TextArea
* OUTPUT:
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import net.mindview.util.*;
public class TextArea extends JFrame {
private JButton b = new JButton("Add Data");
private JButton c = new JButton("Clear Data");
private JTextArea t = new JTextArea(20, 40);
private Map<String, String> m = new HashMap<String, String>();
public TextArea() {
m.putAll(Countries.capitals());
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
for (Map.Entry me : m.entrySet()) {
t.append(me.getKey() + ": " + me.getValue() + "\n");
}
}
});
c.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
t.setText("");
}
});
setLayout(new FlowLayout());
add(new JScrollPane(t));
add(b);
add(c);
}
public static void main(String[] args) {
SwingConsole.run(new TextArea(), 475, 425);
}
}