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
|
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class IGMasterMind extends JFrame {
JRadioButton ovo = new JRadioButton("Ordi vs Ordi");
JRadioButton hvo = new JRadioButton("Humain vs Ordi");
ButtonGroup btchoix = new ButtonGroup();
JLabel choixmode = new JLabel("Choix du mode de jeu : ");
public IGMasterMind()
{
super("MasterMind");
this.setResizable(false);
this.setSize(800,600);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel panel =(JPanel)getContentPane();
GridBagLayout layout = new GridBagLayout();
panel.setLayout(layout);
GridBagConstraints c1 = new GridBagConstraints();
JPanel choixjeu = new JPanel();
btchoix.add(ovo); // n'avoir le choix de lancer qu'un seul des deux modes
btchoix.add(hvo);
choixjeu.add(choixmode);
ovo.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
JLabel coucou = new JLabel("coucou");
JButton coul = new JButton("Générer couleur");
GridBagConstraints c2 = new GridBagConstraints();
JPanel pa = new JPanel();
pa.add(coucou);
pa.add(coul);
c2.gridx=1;
c2.gridy=1;
c2.weightx=100;
c2.weighty=100;
panel.add(pa,c2);
}
});
//hvo.addActionListener();
choixjeu.add(ovo);
choixjeu.add(hvo);
c1.gridx=2;
c1.gridy=0;
c1.fill = GridBagConstraints.HORIZONTAL;
c1.insets = new Insets(1,0,0,0);
c1.weightx=0;
c1.weighty=0;
panel.add(choixjeu,c1);
}
public static void main (String [] args)
{
IGMasterMind m = new IGMasterMind();
}
} |
Partager