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 98 99
| package ecluse2;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Fenetre extends JFrame implements ActionListener
{
private JPanel pan = new JPanel();
JButton feuAmont = new JButton ("Feu Amont");
JButton feuAval = new JButton ("Feu Aval");
JLabel feuVertAmont = new JLabel(new ImageIcon(Fenetre.class.getResource("feuvert.png")));
JLabel bateau = new JLabel(new ImageIcon(Fenetre.class.getResource("bateau.png")));
JLabel feuRougeAmont = new JLabel(new ImageIcon(Fenetre.class.getResource("feurouge.png")));
JLabel feuRougeAval= new JLabel(new ImageIcon(Fenetre.class.getResource("feurouge.png")));
JLabel feuVertAval= new JLabel(new ImageIcon(Fenetre.class.getResource("feuVert.png")));
public void paint (Graphics g)
{
super.paint(g);
g.setColor(Color.darkGray); // rectangle bas
g.fillRect(0, 520, 1000, 80);
g.setColor(Color.blue); // porte amont
g.fillRect(350, 300, 20, 220);
g.setColor(Color.blue); // porte aval
g.fillRect(650, 300, 20, 220);
g.setColor(Color.CYAN); // mer amont
g.fillRect(0, 370, 350, 150);
g.setColor(Color.CYAN); // mer aval
g.fillRect(670, 460, 350, 60);
g.setColor(Color.CYAN); // mer milieu haut
g.fillRect(370, 370, 280, 150);
g.setColor(Color.pink); // mer milieu bas
g.fillRect(370, 460, 280, 60);
}
public Fenetre ()
{
JLayeredPane lp = new JLayeredPane();
this.setTitle ("Gestion d'une écluse");
this.setSize (1000,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.setResizable(false); // interdit redimensionnement
this.setContentPane(pan);
this.setLayout(null);
bateau.setBounds(200, 215, 150, 150);
feuVertAmont.setBounds(200, 60, 300, 300);
feuRougeAmont.setBounds(200, 60, 300, 300);
feuRougeAval.setBounds(500, 60, 300, 300);
feuVertAval.setBounds(500, 60, 300, 300);
feuAmont.setBounds(0, 10, 150, 50);
feuAval.setBounds(151, 10, 150, 50);
pan.add(bateau);
pan.add(feuRougeAmont);
pan.add(feuVertAmont);
pan.add(feuRougeAval);
pan.add(feuVertAval);
pan.add(feuAmont);
pan.add(feuAval);
feuAmont.addActionListener(this);
feuAval.addActionListener(this);
}
public void actionPerformed (ActionEvent a)
{
Object source = a.getSource();
if (source == feuAmont )
{
if (Feu.fAmont.getCouleurFeu()== CouleurFeu.ROUGE)
{
Feu.fAmont.setCouleurFeu(CouleurFeu.VERT);
feuVertAmont.setBounds(200, 60, 300, 300);
}
else
{Feu.fAmont.setCouleurFeu(CouleurFeu.ROUGE);
feuRougeAmont.setBounds(200, 60, 300, 300);
}
}
else
if (source == feuAval )
System.out.println("bouton feu aval cliqué");
}
} |
Partager