This is an animated java applet I made that shows a falling apple.
GeSHi (java):
package house;
import java.applet.Applet;
import java.awt.*;
int ani1 = 0, apple = 60, x = 0, delay = 0;
boolean appleDelay = true;
g.
setColor (Color.
BLACK);
g.drawLine (120, 40, 60, 70);
g.drawLine (120, 40, 180, 70);
g.drawRect (60, 70, 120,70);
g.
setColor (Color.
yellow);
g.fillRect (61, 70, 119,70);
g.drawRect (70, 100, 30,40);
g.
setColor (Color.
orange);
g.fillRect (70, 100, 30,40);
g.drawRect (120,100, 20,20);
g.fillRect (120,100, 20,20);
g.fillRect (150,100, 20,20);
g.
setColor (new Color (255,
192,
81));
g.fillRect (240,70, 20,70);
g.
setColor (Color.
green);
g.fillOval (220, 20, 70, 70);
g.drawString("An animated Applet :: www.engineeringserver.com", 100,200);
g.
setColor(Color.
yellow);
g.fillOval(400,10,50,50);
getRandom();
if (x == 1){
g.drawLine(395, 20, 350, 10);
g.drawLine(395, 35, 370, 35);
g.drawLine(395, 50, 350, 60);
g.drawLine(410, 60, 380, 70);
ani1++;
}
if (x == 2){
g.drawLine(395, 35, 370, 35);
g.drawLine(410, 60, 380, 70);
ani1++;
}
if (x == 3){
g.drawLine(395, 20, 350, 10);
g.drawLine(395, 50, 350, 60);
ani1++;
}
if (x == 4){
g.drawLine(395, 20, 350, 10);
g.drawLine(410, 60, 380, 70);
ani1++;
}
else{
ani1--;
}
g.fillOval(240, 60, 10, 10);
g.fillOval(250, 25, 10, 10);
g.fillOval(225, 40, 15, 15);
g.fillOval(265, apple, 15, 15);
}
public void init(){}
public void appleAni(){
if (apple <=120 && appleDelay== false){
apple = apple+5;
}
}
public void getRandom(){
x =
(int) (1 *
Math.
random()*
5);
}
public void start(){
imageThread =
new Thread(this,
"");
imageThread.start();
}
public void destroy(){}
public void run() {
while(Thread.
currentThread() == imageThread
){ try {
t.sleep(500);
appleAni();
delay++;
repaint();
if( delay ==10){
appleDelay = false;
}
e.printStackTrace();
}
}
}
}
Created by GeSHI 1.0.7.20