Simple Applet Project
Code For The Project
public class Assignment extends Applet implements Runnable {
Image Picture;
public void init() {
Thread t = new Thread(this);
t.start();
Picture = getImage(getDocumentBase(),"water.gif");
}
int i,j;
public void paint(Graphics g)
{
resize(800,600);
drawPaint(i+20,200+j,g);
drawBoat(i+20,200+j,g);
drawBoat((-i)+800,200+j,g);
g.drawImage (Picture, 0, 300, this);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
Logger.getLogger(Assignment.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void drawBoat(int x,int y, Graphics g){
int z = x;
g.setColor(Color.gray);
int xpoint[] = {-20+z,200+z,80+z};
int ypoint[] = {400,400,600};
int point = 3;
g.fillPolygon(xpoint, ypoint, point);
g.setColor(Color.green);
int xpoints[] = {70+z,200+z,80+z};
int ypoints[] = {400,400,200};
int points = 3;
g.fillPolygon(xpoints, ypoints, points);
}
public void drawPaint(int x,int y,Graphics g)
{
g.setColor(Color.CYAN);
g.fillRect(0, -200, 800, 800);
g.setColor(Color.red);
g.fillOval(x, y, 100, 100);
}
@Override
public void run() {
try
{
Thread.sleep(2000);
}
catch(InterruptedException ex)
{
}
while(true)
{
for(i=(-30),j=0;i<400;i+=5,j-=2)
{
repaint();
try{
Thread.sleep(100);
}
catch(InterruptedException ex)
{
}
}
for(i=400,j=-172;i<800;i+=5,j+=2)
{
repaint();
try{
Thread.sleep(100);
}
catch(InterruptedException ex)
{
}
}
}
}
}
Note: How to add image/.gif
1. Code the program
2. Clean and Build the program
3. Add image into build folder of your project
4. Run
Comments
Post a Comment