Code source de l'applet "FORMES"
import java.applet.*;
import java.awt.*;
import java.awt.geom.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.text.DecimalFormat;
public class formes extends Applet implements ItemListener
{ private static final long serialVersionUID = 1420972181089578L;
Font font = new Font("SansSerif",1,12);
Font small = new Font("Serif",0,9);
Image ima; Graphics h;
int la,ha;
int Xs,Ys;
FlowLayout fl= new FlowLayout(1,25,8);
Checkbox cb1;
Object cren=RenderingHints.VALUE_ANTIALIAS_OFF;
Polygon poly1,poly2;
boolean anticren=false;
float motif []= {10.0f,2.0f,2f,2f};
BasicStroke point=new BasicStroke(1.0f,0,0,5.0f,motif,2.0f);
BasicStroke epais2=new BasicStroke(2.f,0,0);
BasicStroke normal= new BasicStroke();
DecimalFormat f20=new DecimalFormat("0.00");
public void init()
{ resize(600,300);
setBackground(Color.lightGray);
setFont(font);
la=getWidth(); ha=getHeight();
ima=createImage(la,ha);
h=ima.getGraphics();
setLayout(fl);
add(cb1 = new Checkbox("Anticrénelage",false));
cb1.addItemListener(this);}
public void itemStateChanged(ItemEvent evt)
{ if (evt.getSource()==cb1){
anticren=!anticren;
if (anticren)cren=RenderingHints.VALUE_ANTIALIAS_ON;
else cren=RenderingHints.VALUE_ANTIALIAS_OFF;}
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);
h.setFont(font);
Graphics2D g2=(Graphics2D)h;
g2.setColor(Color.black);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,cren);
g2.draw(new Line2D.Double(50,50,550,70));
g2.draw(new Line2D.Float(50.5f,60,60,250));
poly1=new Polygon();
poly1.addPoint(70,110); poly1.addPoint(80,70);
poly1.addPoint(140,150); poly1.addPoint(110,140);
poly1.addPoint(90,160);
g2.draw(poly1);
poly2=new Polygon();
poly2.addPoint(70,210); poly2.addPoint(80,170);
poly2.addPoint(140,250); poly2.addPoint(110,240);
poly2.addPoint(90,260);
g2.fill(poly2);
g2.setColor(Color.yellow); g2.fill(new Ellipse2D.Float(170,70,80,90));
g2.setColor(Color.black); g2.draw(new Ellipse2D.Double(170,70,80,90));
g2.draw(new Ellipse2D.Double(170,180,80,90));
g2.draw(new Arc2D.Double(280,70,50,50,60,270,Arc2D.Double.OPEN));
g2.fill(new Arc2D.Double(280,130,50,50,60,270,Arc2D.Double.PIE));
g2.draw(new Arc2D.Double(280,210,50,60,110,270,Arc2D.Double.CHORD));
h.drawString("OPEN",300,95);
h.drawString("PIE",320,155);
h.drawString("CHORD",285,245);
g2.draw(new RoundRectangle2D.Double(370,80,80,90,20,20));
g2.fill(new Rectangle2D.Double(370,180,80,90));
h.drawRect(480,100,50,100);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
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();}
}