//: c13:TextArea.java // Przykład z książki 'Thinking in Java, wydanie 2.', autor - Bruce Eckel // www.BruceEckel.com // Patrz informacje o prawach autorskich podane w pliku CopyRight.txt. // Użycie kontrolki JTextArea. // <applet code=TextArea width=475 height=425> // </applet> import javax.swing.*; import java.awt.event.*; import java.awt.*; import java.util.*; import com.bruceeckel.swing.*; import com.bruceeckel.util.*; public class TextArea extends JApplet { JButton b = new JButton("Dodaj dane"), c = new JButton("Wyczyść dane"); JTextArea t = new JTextArea(20, 40); Map m = new HashMap(); public void init() { // Wykorzystaj wszystkie dane: Collections2.fill(m, Collections2.geography, CountryCapitals.pairs.length); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ for(Iterator it= m.entrySet().iterator(); it.hasNext();){ Map.Entry me = (Map.Entry)(it.next()); t.append(me.getKey() + ": " + me.getValue() + "\n"); } } }); c.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e){ t.setText(""); } }); Container cp = getContentPane(); cp.setLayout(new FlowLayout()); cp.add(new JScrollPane(t)); cp.add(b); cp.add(c); } public static void main(String[] args) { Console.run(new TextArea(), 475, 425); } } ///:~