1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public 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;
private GridBagConstraints gbc = new GridBagConstraints();
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 finPanel = new JPanel(new GridBagLayout());
JPanel pan1 = new JPanel(new GridLayout(0,1));
JLabel LAB_NS = new JLabel("Veuillez choisir un niveau");
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);
// on ajoute le premier panel à notre finPanel
// dans la case 0 0 au nord ouest
gbc.gridx=0;
gbc.gridy=0;
gbc.anchor=GridBagConstraints.NORTHWEST ;
finPanel.add(pan1,gbc);
// 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);
//on ajoute le premier panel à notre finPanel
//dans la case 0 0 au nord EST
gbc.gridx=1;
gbc.gridy=0;
gbc.anchor=GridBagConstraints.NORTHEAST ;
finPanel.add(pan2,gbc);
JPanel panBoutonAfficher = new JPanel( new FlowLayout(FlowLayout.CENTER));
this.getContentPane().add("Center",finPanel);
this.getContentPane().add("North",LAB_NS);
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 |
Partager