Friday 8 March 2013


 PROGRAM- 1

   BOUNCING BALL

import java.awt.*;
import java.awt.image.*;
import java.applet.*;
/*<applet code="ball.class" width=810 height=600></applet>*/
public class ball extends Applet implements Runnable
{
int x,y,d=20,height;
private Image img;
private Graphics g2;
public boolean fall;
int r,h;
double delay=4;
public void init()
{
x=0;
y=0;
r=d/2;
height=500;
fall=true;
}
public void start()
{
Thread thread=new Thread(this);
thread.start();
}
public void run()
{
while(true)
{
if(fall && y<530){
y++;
if(y%3==0)x++;
delay-=.003;
}
else if(!fall && y>h)
{
y--;
if(y%3==0)x++;
delay+=0.003;
}
if(y>=525)
{fall=false;height=height*2/3;}
if(y<=h)
{fall=true;y=h;}
repaint();
try{
Thread.sleep((int)delay);
} catch(InterruptedException e) {
e.printStackTrace();
}
}
}
public void update(Graphics g)
{
if(img==null){
img=createImage(this.getSize().width,this.getSize().height);
g2=img.getGraphics();
}
g2.clearRect(0,0,this.getSize().width,this.getSize().height);
paint(g2);
g.drawImage(img,0,0,this);
}
public void paint(Graphics g)
{
g.drawLine(0,550,810,550);
g.fillOval(x,y,d,d);
h=530-height;
}
}

1 comment:

  1. Betway Casino Site | 2021 Review and Ratings - LuckyClub
    Betway Casino Review · Welcome Bonus · Mobile casino · Live casino · Live chat · Welcome Bonus · Live customer support · Live luckyclub.live chat · Live customer support

    ReplyDelete