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
|
import javax.swing.*; import java.awt.event.*;
import java.awt.*; import javax.swing.event.*;
class Fenetre extends JFrame implements ActionListener
{
JButton bouton1, bouton2, bouton3, bouton4;
JPanel p1, p2;
JTextField champ;
JRadioButton b1, b2;
public Fenetre()
{
setTitle("arrête programme");
setSize(400, 200);
Container c = getContentPane();
p1 = new JPanel();
p1.setBackground(new Color(0, 190, 0));
c.add(p1, "North");
p2 = new JPanel();
p2.setBackground(new Color(190, 0, 0));
c.add(p2, "South");
ButtonGroup gr = new ButtonGroup();
b1 = new JRadioButton("Adulte");
b1.addActionListener(this);
b2 = new JRadioButton("Enfant");
b2.addActionListener(this);
gr.add(b1);
gr.add(b2);
p1.add(b1);
p1.add(b2);
bouton1 = new JButton("Travailleur");
bouton2 = new JButton("Chômeur");
bouton3 = new JButton("Scolarisé");
bouton4 = new JButton("Non scolarisé");
p2.add(bouton1);
p2.add(bouton2);
p2.add(bouton3);
p2.add(bouton4);
bouton1.setVisible(false);
bouton2.setVisible(false);
bouton3.setVisible(false);
bouton4.setVisible(false);
setLocationRelativeTo(this.getParent());
setDefaultCloseOperation(3);
}
public void actionPerformed(ActionEvent a)
{
if(a.getSource() == b1)
{
bouton1.setVisible(true);
bouton2.setVisible(true);
bouton3.setVisible(false);
bouton4.setVisible(false);
p2.validate();
}
else
{
bouton1.setVisible(false);
bouton2.setVisible(false);
bouton3.setVisible(true);
bouton4.setVisible(true);
p2.validate();
}
}
}
public class CreationDeBouton
{
public static void main(String [] args)
{
JFrame f = new Fenetre();
f.setVisible(true);
}
} |
Partager