
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;

// Beispiel mit Radiobuttons
// Einfügen der Radiobuttons
// richtige Reihenfolge


public class RadioButton03 extends JFrame {
  JLabel label;
  JRadioButton rb1;
  JRadioButton rb2;
  JRadioButton rb3;
  JRadioButton rb4;

  JRadioButton rb5;
  JRadioButton rb6;
  JRadioButton rb7;
  JRadioButton rb8;

  //Frame konstruieren
  public RadioButton03() {
    setSize(300, 200);
    setTitle("Beispiel Radiobutton03");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  void setGUI() {
    JPanel panel1;
    JLabel label1;
    JLabel label2;
    ButtonGroup group1;
    ButtonGroup group2;

    setSize(400, 300);

    label1 = new JLabel("1. Auswahl");
    label2 = new JLabel("2. Auswahl");

    rb1 = new JRadioButton("1. Wahl", false);
    rb2 = new JRadioButton("2. Wahl", true);
    rb3 = new JRadioButton("3. Wahl", false);
    rb4 = new JRadioButton("4. Wahl", false);

    rb5 = new JRadioButton("A. Wahl", false);
    rb6 = new JRadioButton("B. Wahl", false);
    rb7 = new JRadioButton("C. Wahl", true);
    rb8 = new JRadioButton("D. Wahl", false);

    label1.setFont( new Font("Arial", Font.BOLD, 18)  );
    label2.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb1.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb2.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb3.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb4.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb5.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb6.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb7.setFont( new Font("Arial", Font.BOLD, 18)  );
    rb8.setFont( new Font("Arial", Font.BOLD, 18)  );

    group1 = new ButtonGroup();
    group1.add(rb1);
    group1.add(rb2);
    group1.add(rb3);
    group1.add(rb4);

    group2 = new ButtonGroup();
    group2.add(rb5);
    group2.add(rb6);
    group2.add(rb7);
    group2.add(rb8);

    panel1 = new JPanel();
    panel1.setLayout ( new GridLayout(5,2) ); // 5 Zeilen , 2 Spalte
    this.getContentPane().add(panel1, BorderLayout.CENTER);
    panel1.add( label1 );
    panel1.add( label2 );


    panel1.add( rb1 );
    panel1.add( rb5 );

    panel1.add( rb2 );
    panel1.add( rb6 );
    rb1.setSelected(true);
    rb3.setSelected(true);
    // rb1.isSelected();

    panel1.add( rb3 );
    panel1.add( rb7 );

    panel1.add( rb4 );
    panel1.add( rb8 );


  } // setGUI




  public static void main(String[] args) {
    RadioButton03 frame = new RadioButton03();
    frame.setVisible(true);
  }


}




