From 04f65d22fed81577a5c538800bf1208f33bf7249 Mon Sep 17 00:00:00 2001 From: riham jawad Date: Wed, 1 Mar 2017 15:29:35 +0100 Subject: [PATCH] partie1Exo2 --- src/Partie1Exo2.java | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100755 src/Partie1Exo2.java diff --git a/src/Partie1Exo2.java b/src/Partie1Exo2.java new file mode 100755 index 0000000..d8908de --- /dev/null +++ b/src/Partie1Exo2.java @@ -0,0 +1,91 @@ + +import java.awt.event.*; +import javax.swing.*; +import java.awt.*; +import com.sun.xml.internal.ws.api.server.Container; + + + +public class Partie1Exo2 extends JFrame +{ + //JLabel label ; + public Partie1Exo2(){ + super("Partie1, Exercice2"); + setDefaultCloseOperation(EXIT_ON_CLOSE); + setVisible(true); + + JButton button1 = new JButton("Rouge"); + JButton button2 = new JButton("Blue"); + JButton button3 = new JButton("Quitter"); + JLabel label = new JLabel("Exemple"); + JPanel panel = new JPanel(); + + java.awt.Container con = getContentPane(); + + con.setLayout(new BorderLayout()); + panel.setLayout(new FlowLayout()); + + + panel.add(button1); panel.add(button2); panel.add(button3); + + + con.add(label, BorderLayout.NORTH); + + con.add(panel,BorderLayout.CENTER); + + + button1.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + label.setForeground(Color.RED); + } + }); + button2.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + label.setForeground(Color.blue); + } + }); + button3.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + System.exit(0); + } + }); + + + + + + + + + + + + + + pack(); + + + } + + + + + public static void main(String[] args) { + + SwingUtilities.invokeLater(() -> gui()); + + + } + private static void gui() { + // thread: GUI + new Partie1Exo2(); + } + +} + -- GitLab