Code :
package fr.language; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; private static final long serialVersionUID = 1L; private int num1 = 2; public Toto() { setBounds(400, 60, 600, 650); setResizable(false); setDefaultCloseOperation (JFrame. EXIT_ON_CLOSE); setLayout(null); // A éviter! verbe.setBounds(150, 0, 150, 30); verbe.addActionListener(this); voc.setBounds(300, 0, 150, 30); voc.addActionListener(this); j1.setBounds(0, 85, 600, 40); j1.add(b1); j2.setBounds(0, 60, 600, 480); j2.add(b2); jbInit(); } public void jbInit() { System. out. println("num:" + num1 ); content.removeAll(); content.add(voc); content.add(verbe); switch (num1) { case 2: content.add(j1); break; case 3: content.add(j2); } } if (e.getSource() == voc) { num1 = 3; jbInit(); // Réarrange les composants actuellement affichés getContentPane().validate(); repaint(); } } public static void main (String[] args ) { new Toto().setVisible(true); } }
|