import java.awt.*; import java.applet.Applet; public class auto3 extends Applet { static car anf=null; static Image im=null; static Graphics gi=null; public void init() { im=createImage(1024,120); gi=im.getGraphics(); setSize(1024,120); anf=new car(100,Color.blue,0,3,anf); anf=new car(200,Color.black,25,1,anf); anf=new car(300,Color.red,10,2,anf); } void zeichnen() { car a=anf; gi.setColor(new Color(200,230,255)); gi.fillRect(0,0,1024,77); gi.setColor(Color.green); gi.fillRect(0,77,1024,48); for (;a!=null;a=a.nxt) a.bild(gi,anf); } public void update(Graphics g) { zeichnen(); g.drawImage(im,0,0,this); try{Thread.sleep(10);} catch(Exception e){}; repaint(); } public void paint(Graphics g) { System.out.println("fiffi"); repaint(); } } class car { public int po; //po: Position int fo,vm; //fo: Form, vm: max.Geschwindigkeit double v; //v: reale Geschwindigkeit Color co; //co: Wagenfarbe car nxt=null; public car(int xa,Color aco,int fof,int vmx,car altanf) { //Konstruktor deklarieren po=xa;co=aco;fo=fof;vm=vmx;v=vm; nxt=altanf; } public void bild(Graphics g, car anf) { int x[]=new int[4],y[]=new int[4]; //Deklarationen für Punktkoordinaten g.setColor(co); //Farbe einstellen g.fillRect(po,60,60,12); //unteres Rechteck x[0]=po+10;y[0]=60;x[1]=po+25;y[1]=50; //Punktkoordinaten x[2]=po+fo+34;y[2]=50; x[3]=po+59;y[3]=60; g.drawPolygon(x,y,4); //obere Fensterfläche g.drawLine(po+34,51,po+32,59); //Trennlinie im oberen Trapez g.setColor(new Color(80,80,100)); //Farbe Anthrazit g.fillOval(po+7,67,10,10); //Vorderrad g.fillOval(po+40,67,10,10); //Hinterrad if(dist(anf)<50) v=(int)(v*dist(anf)/100); //Bremsen bei Abstand unter 50 if(dist(anf)>70)v=Math.min(v*1.5,vm); //Beschleunigen bei Abstand über 70 po=po-(int)v; //Position berechnen if (po<0) po=1024; } int dist(car anf){ return 100; } }