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
|
import java.applet.Applet;
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Circuit1 extends Applet implements ActionListener
{
Button b;
Button bu;
private boolean etatCircuit;
public void init ()
{
etatCircuit=false;
setLayout(new FlowLayout());
b = new Button("Circuit Ouvert");
bu = new Button("Circuit Fermé");
add(b); add(bu);
b.addActionListener(this);
bu.addActionListener(this);
}
public void paint (Graphics g)
{
if(etatCircuit)
dessinerCircuitFerme(g);
else
dessinerCircuitOuvert(g);
}
private void dessinerCircuitOuvert(Graphics g)
{
int RAYON = 20; int u = 209; int i = 280;
setSize(460, 350);
g.setColor (Color.white);
g.fillRect (0, 0, getSize().width, getSize().height);
Rectangle r = new Rectangle(50,100,350,200);
Rectangle re = new Rectangle(40,170,20,50);
g.setColor(Color.black);
g.fillRect(re.x,re.y,re.width,re.height);
g.setColor(Color.black);
g.drawRect(r.x,r.y,r.width,r.height);
g.setColor(Color.WHITE);
g.fillOval (u,i, RAYON* 2, RAYON* 2);
g.setColor(Color.black);
g.drawOval (u,i, RAYON* 2, RAYON* 2);
}
private void dessinerCircuitFerme(Graphics g)
{
//on dessine le circuit ferme
}
public void actionPerformed(ActionEvent evt ) {
if( evt.getSource() == b)
{
etatCircuit=false;
repaint();
}
else if(evt.getSource()==bu)
{
etatCircuit=true;
rePaint();
}
}
} |
Partager