forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextArea.java
More file actions
34 lines (33 loc) · 1010 Bytes
/
Copy pathTextArea.java
File metadata and controls
34 lines (33 loc) · 1010 Bytes
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
// ui/TextArea.java
// (c)2016 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
// Using the JTextArea control
import javax.swing.*;
import java.awt.*;
import java.util.*;
import onjava.*;
import static onjava.SwingConsole.*;
public class TextArea extends JFrame {
private JButton
b = new JButton("Add Data"),
c = new JButton("Clear Data");
private JTextArea t = new JTextArea(20, 40);
private Map<String,String> m = new HashMap<>();
public TextArea() {
// Use up all the data:
m.putAll(Countries.capitals());
b.addActionListener(e -> {
for(Map.Entry me : m.entrySet())
t.append(me.getKey() + ": "+ me.getValue()+"\n");
});
c.addActionListener(e -> t.setText(""));
setLayout(new FlowLayout());
add(new JScrollPane(t));
add(b);
add(c);
}
public static void main(String[] args) {
run(new TextArea(), 475, 425);
}
}