import java.awt.*;
import java.applet.*;
import java.net.*;
/*<applet code="MovingCar" width="1340" height="580"></applet>*/
public class MovingCar extends Applet
{
int x=15,y=15;
int r1=20,r2=115;
int r3=161,r4=115;
Image img;
URL u1;
public void init()
{
setBackground(Color.BLUE);
setForeground(Color.BLACK);
}
public void paint(Graphics g1)
{
u1=getCodeBase();
img=getImage(u1,"3.png");
while(true)
{
g1.drawRect(x,y,200,100);
g1.fillOval(r1,r2,50,50);
g1.fillOval(r3,r4,50,50);
g1.drawImage(img,x,y+400,this);
x++;r1++;r3++;
try
{
Thread.sleep(10);
}
catch(InterruptedException e)
{
e.getMessage();
}
if(x>getSize().width)
{
x=15;
y=15;
r1=20;
r3=161;
r2=115;
r4=115;
}
g1.clearRect(0,0,getSize().width,getSize().height);
}
}
}
download this image to see image moving with car
import java.applet.*;
import java.net.*;
/*<applet code="MovingCar" width="1340" height="580"></applet>*/
public class MovingCar extends Applet
{
int x=15,y=15;
int r1=20,r2=115;
int r3=161,r4=115;
Image img;
URL u1;
public void init()
{
setBackground(Color.BLUE);
setForeground(Color.BLACK);
}
public void paint(Graphics g1)
{
u1=getCodeBase();
img=getImage(u1,"3.png");
while(true)
{
g1.drawRect(x,y,200,100);
g1.fillOval(r1,r2,50,50);
g1.fillOval(r3,r4,50,50);
g1.drawImage(img,x,y+400,this);
x++;r1++;r3++;
try
{
Thread.sleep(10);
}
catch(InterruptedException e)
{
e.getMessage();
}
if(x>getSize().width)
{
x=15;
y=15;
r1=20;
r3=161;
r2=115;
r4=115;
}
g1.clearRect(0,0,getSize().width,getSize().height);
}
}
}
download this image to see image moving with car
No comments:
Post a Comment