Bonjour,
J'ai crée une frame qui conteint deux panels.
chaque panel contient 3 boutons radio avec un chois à faire
-premier panel pour choisir un niveau
-deuxièpe panel pour choisir un style d'enigme.
Je ne parvien spas à obtenir un agencement joli de ces deux panels de manière à ce que l'utilisateur fasse son choix de manière agréable.
Je ne pense pas qu'il y a ait grand chose à changer , peut être un box layout à créer, mais pour l'instant la présenttion ne donne pas satisfaction.
voici le code proposé
[code]
package TP_ENIGME;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Choix_Niveau_Style extends JFrame implements ActionListener
{
public ButtonGroup buttongroupniveau;
public ButtonGroup buttongroupstyle;
private JRadioButton b1;
private JRadioButton b2;
private JRadioButton b3;
private JRadioButton b4;
private JRadioButton b5;
private JRadioButton b6;
private JButton boutonAfficher;
private String niveau;
private String style;
private JLabel LAB_NS;
public Choix_Niveau_Style()
{
this.setTitle("Choix de niveau et de style d'énigme");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//JPanel pan1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
JPanel pan1 = new JPanel(new GridLayout(0,1));
JLabel LAB_NS = new JLabel("Veuillez choisir un niveau");
this.getContentPane().add("North", pan1);
this.getContentPane().add(LAB_NS,"Center");
b1 = new JRadioButton("Niveau Débutant", false);
pan1.add(b1);
b1.setActionCommand("debutant");
b2 = new JRadioButton("Niveau Intermédiaire", false);
pan1.add(b2);
b2.setActionCommand("intermediaire");
b3 = new JRadioButton("Niveau avancé", false);
pan1.add(b3);
b3.setActionCommand("avance");
buttongroupniveau = new ButtonGroup();
buttongroupniveau.add(b1);
buttongroupniveau.add(b2);
buttongroupniveau.add(b3);
// JPanel pan2 = new JPanel();
// this.getContentPane().add("Center", pan2);
JPanel pan2 = new JPanel(new GridLayout(0,1));
this.getContentPane().add("South", pan2);
b4 = new JRadioButton("Probabilités", false);
pan2.add(b4);
b4.setActionCommand("probabilites");
b5 = new JRadioButton("Exploits des 40 voleurs d'Ali Baba", false);
pan2.add(b5);
b5.setActionCommand("ali baba");
b6 = new JRadioButton("A propos des Mazdéens et des Aharmanites", false);
pan2.add(b6);
b6.setActionCommand("A propos des mazdéens et des Aharmanites");
buttongroupstyle = new ButtonGroup();
buttongroupstyle.add(b4);
buttongroupstyle.add(b5);
buttongroupstyle.add(b6);
JPanel panBoutonAfficher = new JPanel( new FlowLayout(FlowLayout.CENTER));
this.getContentPane().add("South", panBoutonAfficher);
boutonAfficher = new JButton("AFFICHER");
panBoutonAfficher.add(boutonAfficher);
boutonAfficher.addActionListener(this);
pack();
setVisible(true);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} // fin du constructeur
public void actionPerformed(ActionEvent e)
{
niveau = this.buttongroupniveau.getSelection().getActionCommand();
style = this.buttongroupstyle.getSelection().getActionCommand();
System.out.println( "niveau_choisi: "+niveau + " et style_choisi : " +style);
Object source = e.getSource();
if(source == boutonAfficher)
AfficheEnigme() ;
}// fin Action Performed
private void AfficheEnigme()
{
GestionEnigmes C2= new GestionEnigmes(niveau, style);
this.setVisible(false);
}// fin de AffichEnigDeb()
public static void main(String[] args)
{
Choix_Niveau_Style CN2 = new Choix_Niveau_Style();
// CN2.show();
CN2.pack();
CN2.setVisible(true);
}
} //fin de classe Choix_Niveau_Style
Merci beaucoup de votre aide toujours très efficace et précieuse.
Cordialement.
Nathalie
Partager