summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java58
1 files changed, 58 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java
new file mode 100644
index 0000000..b271396
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java
@@ -0,0 +1,58 @@
+/* Listing3710.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import javax.swing.*;
+
+public class Listing3710
+extends JFrame
+implements ActionListener
+{
+ static final String[] DATA = {
+ "Hund", "Katze", "Meerschweinchen", "Tiger", "Maus",
+ "Fisch", "Leopard", "Schimpanse", "Kuh", "Pferd",
+ "Reh", "Huhn", "Marder", "Adler", "Nilpferd"
+ };
+
+ private JList list;
+
+ public Listing3710()
+ {
+ super("JList");
+ addWindowListener(new WindowClosingAdapter(true));
+ Container cp = getContentPane();
+ //Liste
+ list = new JList(DATA);
+ list.setSelectionMode(
+ ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
+ );
+ list.setSelectedIndex(2);
+ cp.add(new JScrollPane(list), BorderLayout.CENTER);
+ //Ausgabe-Button
+ JButton button = new JButton("Ausgabe");
+ button.addActionListener(this);
+ cp.add(button, BorderLayout.SOUTH);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Ausgabe")) {
+ System.out.println("---");
+ ListModel lm = list.getModel();
+ int[] sel = list.getSelectedIndices();
+ for (int i = 0; i < sel.length; ++i) {
+ String value = (String)lm.getElementAt(sel[i]);
+ System.out.println(" " + value);
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ Listing3710 frame = new Listing3710();
+ frame.setLocation(100, 100);
+ frame.setSize(200, 200);
+ frame.setVisible(true);
+ }
+} \ No newline at end of file