From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3710.java | 58 ++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3710.java') 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 -- cgit v1.2.3