import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; enum Niveau { FACILE, MOYEN, DIFFICILE; } class FenetreDialogueBis extends JDialog { final JTextField champNom = new JTextField(10); Niveau[] niveaux = {Niveau.FACILE, Niveau.MOYEN, Niveau.DIFFICILE}; final JComboBox choixNiveau = new JComboBox(niveaux); FenetreDialogueBis() { final JOptionPane panneauDialogue; setTitle("Choix"); setModal(true); Object[] lesObjets = {"Indiquez un nom", champNom, "Indiquez un niveau", choixNiveau}; Object[] options = {"Valider"}; panneauDialogue = new JOptionPane (lesObjets, JOptionPane.QUESTION_MESSAGE, 0, null, options); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); setContentPane(panneauDialogue); panneauDialogue.addPropertyChangeListener (new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { panneauDialogue.setValue(JOptionPane.UNINITIALIZED_VALUE); setVisible(false); } }); pack(); setLocation(300, 200); } } class JeuBis extends Box { String nom = ""; Niveau niveau = Niveau.FACILE; JLabel afficheNom = new JLabel(" le nom est : " + nom); JLabel afficheNiveau = new JLabel(" le niveau est : " + niveau + " "); JeuBis() { super(BoxLayout.Y_AXIS); final JButton choix = new JButton("choix"); add(afficheNom); add(afficheNiveau); add(choix); final FenetreDialogueBis dialogue = new FenetreDialogueBis(); choix.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { dialogue.setVisible(true); nom = dialogue.champNom.getText(); niveau = (Niveau)dialogue.choixNiveau.getSelectedItem(); afficheNom.setText(" le nom est : " + nom); afficheNiveau.setText(" le niveau est : " + niveau); } }); } public static void main(String[] arg) { JFrame cadre = new JFrame("Jeu"); cadre.setContentPane(new JeuBis()); cadre.setLocation(100, 200); cadre.pack(); cadre.setVisible(true); } }