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/Listing3709.java | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java new file mode 100644 index 0000000..76f17f4 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3709.java @@ -0,0 +1,52 @@ +/* Listing3709.java */ + +import java.awt.*; +import java.awt.event.*; +import javax.swing.*; + +public class Listing3709 +extends JFrame +implements ActionListener +{ + private ButtonGroup group = new ButtonGroup(); + + public Listing3709() + { + super("JRadioButton"); + addWindowListener(new WindowClosingAdapter(true)); + //RadioButton-Panel + JPanel panel = new JPanel(); + panel.setLayout(new GridLayout(3, 1)); + for (int i = 1; i <= 3; ++i) { + JRadioButton rb = new JRadioButton("RadioButton" + i, i == 2); + rb.setActionCommand(rb.getText()); + panel.add(rb); + group.add(rb); + } + getContentPane().add(panel, BorderLayout.CENTER); + //Selektion-Button + JButton button = new JButton("Selektion"); + button.addActionListener(this); + getContentPane().add(button, BorderLayout.SOUTH); + } + + public void actionPerformed(ActionEvent event) + { + String cmd = event.getActionCommand(); + if (cmd.equals("Selektion")) { + ButtonModel selected = group.getSelection(); + System.out.print("Selektiert: "); + if (selected != null) { + System.out.println(selected.getActionCommand()); + } + } + } + + public static void main(String[] args) + { + Listing3709 frame = new Listing3709(); + frame.setLocation(100, 100); + frame.setSize(300, 120); + frame.setVisible(true); + } +} \ No newline at end of file -- cgit v1.2.3