Code source de l'applet "AIRES"
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class aires extends Applet implements ItemListener
{ private static final long serialVersionUID = 1420972181089579L;
Font font = new Font("SansSerif",1,12);
Font small = new Font("Serif",0,9);
Image ima; Graphics h;
int la,ha;
int token=0,mode=0;
FlowLayout fl= new FlowLayout(1,50,5);
CheckboxGroup bg1 = new CheckboxGroup();
Checkbox cb1,cb2;
Choice chtoken = new Choice();
Shape rond=new Ellipse2D.Double(50,50,160,100);
Shape carre=new Rectangle2D.Double(150,90,80,100);
public void init()
{ resize(600,250);
setBackground(Color.lightGray);
setFont(font);
la=getWidth(); ha=getHeight();
ima=createImage(la,ha);
h=ima.getGraphics();
setLayout(fl);
add(cb1 = new Checkbox("Uniforme",bg1,true));
cb1.addItemListener(this);
chtoken.addItem("Add");
chtoken.addItem("Subtract");
chtoken.addItem("Intersect");
chtoken.addItem("ExclusiveOr");
add(chtoken);
chtoken.addItemListener(this);
chtoken.setBackground(Color.lightGray);
add(cb2 = new Checkbox("Dégradés",bg1,false));
cb2.addItemListener(this);}
public void itemStateChanged(ItemEvent evt)
{ if (evt.getSource()==cb1){mode=0;}
else if (evt.getSource()==cb2){mode=1;}
else if (evt.getSource()==chtoken){token=chtoken.getSelectedIndex();}
repaint();}
public void cadre3D(int x, int y, int w, int z)
{ Color blanc=new Color(230,230,230),gris =new Color(130,130,130);
h.setColor(gris); h.drawLine(x,y,w,y);
h.drawLine(x,y+1,w-1,y+1); h.drawLine(x,y,x,z);
h.drawLine(x+1,y,x+1,z-1); h.setColor(blanc);
h.drawLine(x,z,w,z); h.drawLine(w,y+1,w,z);
h.drawLine(x+1,z-1,w,z-1); h.drawLine(w-1,y+2,w-1,z);}
public void update(Graphics g)
{ paint(g);}
public void paint(Graphics g)
{ h.setColor(Color.lightGray); h.fillRect(0,0,la,ha);
h.setColor(Color.black); h.drawRect(0,0,la-1,ha-1);
h.setFont(small); h.drawString("jjR 01-2012",25,ha-25);
Graphics2D g2=(Graphics2D)h;
Area A1=new Area(rond);
Area A3=new Area(rond);
Area A2=new Area(carre);
g2.setPaint(Color.gray);
g2.draw(A3); g2.draw(A2);
//forme complexe
switch (token){
case 0 : A1.add(A2); break;
case 1 : A1.subtract(A2); break;
case 2 : A1.intersect(A2); break;
case 3 : A1.exclusiveOr(A2);}
Rectangle R=A1.getBounds();
Paint pt=new GradientPaint(R.x,R.y,Color.blue,R.x+R.width,R.y+R.height,Color.yellow);
if (mode==0)g2.setPaint(Color.yellow); else g2.setPaint(pt);
g2.fill(A1);
g2.setPaint(Color.red); g2.draw(A1);
//rectangle
pt=new GradientPaint(380,60,Color.cyan,280,210,Color.magenta);
if (mode==0)g2.setPaint(Color.cyan); else g2.setPaint(pt);
g2.fillRect(280,60,100,150);
g2.setPaint(Color.black); g2.drawRect(280,60,100,150);
//ellipse
pt=new GradientPaint(330,60,Color.red,330,210,Color.green);
if (mode==0)g2.setPaint(Color.red); else g2.setPaint(pt);
g2.fillOval(450,60,100,150);
g2.setPaint(Color.black); g2.drawOval(450,60,100,150);
cadre3D(20,40,la-20,ha-20);
g.drawImage(ima,0,0,this);
showStatus("J. J. Rousseau 01-2012");}
public void destroy()
{ h.dispose(); ima.flush();}
}