2015-04-20 15:36:01 -07:00
|
|
|
//: gui/TextArea.java
|
|
|
|
// Using the JTextArea control.
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.*;
|
|
|
|
import java.util.*;
|
|
|
|
import net.mindview.util.*;
|
|
|
|
import static net.mindview.util.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);
|
2015-05-05 11:20:13 -07:00
|
|
|
private Map<String,String> m = new HashMap<>();
|
2015-04-20 15:36:01 -07:00
|
|
|
public TextArea() {
|
|
|
|
// Use up all the data:
|
|
|
|
m.putAll(Countries.capitals());
|
2015-05-06 12:09:38 -07:00
|
|
|
b.addActionListener(e -> {
|
2015-05-05 14:05:39 -07:00
|
|
|
for(Map.Entry me : m.entrySet())
|
|
|
|
t.append(me.getKey() + ": "+ me.getValue()+"\n");
|
2015-04-20 15:36:01 -07:00
|
|
|
});
|
2015-05-06 12:09:38 -07:00
|
|
|
c.addActionListener(e -> t.setText(""));
|
2015-04-20 15:36:01 -07:00
|
|
|
setLayout(new FlowLayout());
|
|
|
|
add(new JScrollPane(t));
|
|
|
|
add(b);
|
|
|
|
add(c);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
run(new TextArea(), 475, 425);
|
|
|
|
}
|
|
|
|
} ///:~
|