Thursday, 20 October 2016

Write a java Applet Program For Ball Moving

import java.applet.*;
import java.awt.*;

public class Ball extends Applet implements Runnable
{
int i=0, j=0;
Thread t;
public void init()
{
t=new Thread(this);
t.start();

}
public void run()
{
int sec=0;
setSize (1200,1200);
try
{
while(true)
{
repaint();
sec+=1;
t.sleep(100);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public void update(Graphics g)
{
Paint(g);
}
public void Paint (Graphics g)
{
setBackground(Color.black);
Dimension d=getSize();
g.setColor(Color.black);
g.fillRect(0,0,d.width,d.height);
g.setColor(Color.pink);
g.fillOval(i+10,j+10,100,100);
i=i+10;
g.setColor(Color.black);
}
}


********************************************************************************
HTML CODE

<html>
<applet code="Ball.class" width="800" height="500">
</applet>
</html>

No comments:

Post a Comment