|
@@ -3,13 +3,17 @@ package formation.java.gui.panel;
|
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
|
import java.awt.Container;
|
|
import java.awt.Container;
|
|
|
import java.awt.Dimension;
|
|
import java.awt.Dimension;
|
|
|
|
|
+import java.awt.event.ActionEvent;
|
|
|
|
|
+import java.awt.event.ActionListener;
|
|
|
|
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
|
|
-public class DemonstrationFenetre {
|
|
|
|
|
|
|
+public class DemonstrationFenetre implements ActionListener{
|
|
|
public static void main(String[] args) {
|
|
public static void main(String[] args) {
|
|
|
|
|
+ DemonstrationFenetre df = new DemonstrationFenetre();
|
|
|
|
|
+
|
|
|
JFrame fenetre = new JFrame("Démonstration Panel");
|
|
JFrame fenetre = new JFrame("Démonstration Panel");
|
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
fenetre.setBounds(50, 100, 500, 400);
|
|
fenetre.setBounds(50, 100, 500, 400);
|
|
@@ -25,9 +29,24 @@ public class DemonstrationFenetre {
|
|
|
rouge.setBackground(Color.red);
|
|
rouge.setBackground(Color.red);
|
|
|
rouge.setPreferredSize(new Dimension(30, 20));
|
|
rouge.setPreferredSize(new Dimension(30, 20));
|
|
|
|
|
|
|
|
|
|
+ monBouton.addActionListener(df);
|
|
|
|
|
+ System.out.println(monBouton);
|
|
|
|
|
+
|
|
|
panel.add(monBouton);
|
|
panel.add(monBouton);
|
|
|
panel.add(rouge);
|
|
panel.add(rouge);
|
|
|
|
|
|
|
|
- fenetre.setVisible(true);
|
|
|
|
|
|
|
+ fenetre.setVisible(true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void actionPerformed(ActionEvent e) {
|
|
|
|
|
+ System.out.println("Je suis dans l'action !!! ");
|
|
|
|
|
+ System.out.println(e);
|
|
|
|
|
+
|
|
|
|
|
+ Object unObjet = e.getSource();
|
|
|
|
|
+ if(unObjet instanceof JButton) {
|
|
|
|
|
+ JButton jButton = (JButton) unObjet; //transtypage
|
|
|
|
|
+ jButton.setText("Coucou");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|