import java.awt.event.*;import javax.swing.*;import java.awt.*;public class CL_RadioButton extends JFrame implements ActionListener,FocusListener{ JRadioButton rb_1; JRadioButton rb_2; ButtonGroup bg; public CL_RadioButton() { getContentPane().setLayout(new FlowLayout()); rb_1 = new JRadioButton("RadioButton 1"); rb_2 = new JRadioButton("RadioButton 2"); bg = new ButtonGroup(); bg.add(rb_1); bg.add(rb_2); rb_1.setSelected(true); getContentPane().add(rb_1); getContentPane().add(rb_2); rb_1.addActionListener(this); rb_2.addActionListener(this); rb_1.addFocusListener(this); rb_2.addFocusListener(this); } public void actionPerformed(java.awt.event.ActionEvent e) { if(rb_2.isSelected()) { System.out.println("RadioButton 2 ist selektiert"); } } public void processWindowEvent(WindowEvent e) { if(e.getID() == e.WINDOW_CLOSING) { System.exit(0); } super.processWindowEvent(e); } public static void main (String[] args) { CL_RadioButton rb = new CL_RadioButton(); rb.setSize(120,150); rb.setLocation(200,200); rb.show(); } public void focusGained(java.awt.event.FocusEvent e) { if(e.getSource() == rb_1) { System.out.println("focusGained rb_1"); } } public void focusLost(java.awt.event.FocusEvent e) { Object ereignis = e.getSource(); if(ereignis == rb_2) { System.out.println("focusLost rb_2"); } }}