JRadioButton isEnabled() ?

Status
Nicht offen für weitere Antworten.

xpucto

Mitglied
Wenn der User auf einem Button (Next) Klick möchte ich lesen können, welche Radio Button selektiert wurde. Dafür verwende ich die Methode isEnabled(). Nur Egal welche Radio Button ich selektiere, er sagt mir immer, dass das erste Radio Button selektiert ist. Kann jamand den Fehler sehen?

Code:
public class Niveau extends JPanel {

	protected static ButtonGroup bg;
	protected static JRadioButton A1;
	protected static JRadioButton A2;

	protected static int niveau;
	protected static String subject;
	protected static JButton bNext;

	//Konstruktor
	public Niveau (String subj) {
	subject = subj;
	setLayout(new BorderLayout());
        bNext = new JButton("Suivant",new ImageIcon("graphics/ArrowRight.gif"));
	bg = new ButtonGroup();
        A1 = new JRadioButton("Niveau A1 grand débutant");
        A2 = new JRadioButton("Niveau A2 débutant");

	A1.setSelected(true); 		//A1 schon selektiert, so dass zu mindest ein RadioButton selektiert ist
	Box BoxA = Box.createVerticalBox();

        //Hinfuegen
	bg.add(A1);
	bg.add(A2);

        BoxA.add(A1);
        BoxA.add(A2);

        add(bNext);
	add(BoxA, BorderLayout.WEST);

	add(bNext, BorderLayout.SOUTH);
	//Events
	bNext.addActionListener(new NiveauPanelListener());  //Um zum nächsten Panel zu gehen, wenn ein Niveau selektiert wurde
	}//End Konstruktor

private static class NiveauPanelListener implements ActionListener {
public void actionPerformed(ActionEvent ae)
{
        //Quelle des Ereignisses
        Object quelle = ae.getSource();
        if (quelle == bNext) {
		if (A1.isEnabled()) {
		niveau = 1;
		int wahl  = JOptionPane.showConfirmDialog(null, "Niveau A1", "Grammaire", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
		Escabelle.createGrammaire(subject,niveau);
		}//End if A1.isEnabled
		else if (A2.isEnabled()) {
		niveau = 2;
		int wahl  = JOptionPane.showConfirmDialog(null, "Niveau A2", "Grammaire", JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
		Escabelle.createGrammaire(subject,niveau);
		}//End if A2.selected
        }//End if bNext
}//End actionPerformed
}//End class private
}//End class Niveau
 
Status
Nicht offen für weitere Antworten.

Neue Themen


Zurück
Oben