import java.util.*;
import java.applet.*;
import java.awt.*;
/*
<applet code=carapp width=1000 height=450>
</applet>
*/
public class carapp extends Applet
{
Thread t;
int X[]={314,314,360,360,477,477,530,564};
int Y[]={174,115,115,92,92,114,114,175};
boolean red=false;
int slep;
boolean green=true;
boolean yellow=false;
class car implements Runnable
{
car()
{
for(int x=0;x<8;x++)
{ Y[x]+=100;}
t=new Thread(this,"car");t.start();
}
public void run()
{
for(;;)
{
if(red&&X[7]<600&&X[0]>300)
{
//STOP THE CAR
}
else
for(int x=0;x<8;x++)
{ X[x]+=10;}
repaint();
if(X[0]>1000)
{
for(int x=0;x<8;x++)
{ X[x]-=1200;}
}
try
{
t.sleep(slep);
}catch(Exception e)
{}
}
}
}
class signal implements Runnable
{
signal()
{
t=new Thread(this,"signal");t.start();
}
public void run()
{
while(true)
{
Random r=new Random();
slep=r.nextInt(100);
repaint();
try{
if(green)
{
green=false;
yellow=true;
}else if(yellow)
{
yellow=false;
red=true;
}else if(red)
{
red=false;
green=true;
}
t.sleep(3000);
}catch(Exception e){}
}
}
}
public void init()
{
new car();
new signal();
}
public void paint(Graphics g)
{
//g.drawLine(-1000,200,1000,250);
g.setColor(Color.gray);
g.fillRect(0,170, 1000,150);
g.setColor(Color.red);
g.fillPolygon(X,Y,8);
g.setColor(Color.black);
g.fillOval(20+X[0],255,80,80);
g.setColor(Color.black);
g.fillOval(170+X[0],255,80,80);
g.drawRect(580,90, 50,100);
g.drawOval(600,100,20,20);
g.drawOval(600,130,20,20);
g.drawOval(600,160,20,20);
if(red){
g.setColor(Color.red);
g.fillOval(600,100,20,20);
}
if(yellow){
g.setColor(Color.yellow);
g.fillOval(600,130,20,20);
}
if(green){
g.setColor(Color.green);
g.fillOval(600,160,20,20);
}
}
}
import java.applet.*;
import java.awt.*;
/*
<applet code=carapp width=1000 height=450>
</applet>
*/
public class carapp extends Applet
{
Thread t;
int X[]={314,314,360,360,477,477,530,564};
int Y[]={174,115,115,92,92,114,114,175};
boolean red=false;
int slep;
boolean green=true;
boolean yellow=false;
class car implements Runnable
{
car()
{
for(int x=0;x<8;x++)
{ Y[x]+=100;}
t=new Thread(this,"car");t.start();
}
public void run()
{
for(;;)
{
if(red&&X[7]<600&&X[0]>300)
{
//STOP THE CAR
}
else
for(int x=0;x<8;x++)
{ X[x]+=10;}
repaint();
if(X[0]>1000)
{
for(int x=0;x<8;x++)
{ X[x]-=1200;}
}
try
{
t.sleep(slep);
}catch(Exception e)
{}
}
}
}
class signal implements Runnable
{
signal()
{
t=new Thread(this,"signal");t.start();
}
public void run()
{
while(true)
{
Random r=new Random();
slep=r.nextInt(100);
repaint();
try{
if(green)
{
green=false;
yellow=true;
}else if(yellow)
{
yellow=false;
red=true;
}else if(red)
{
red=false;
green=true;
}
t.sleep(3000);
}catch(Exception e){}
}
}
}
public void init()
{
new car();
new signal();
}
public void paint(Graphics g)
{
//g.drawLine(-1000,200,1000,250);
g.setColor(Color.gray);
g.fillRect(0,170, 1000,150);
g.setColor(Color.red);
g.fillPolygon(X,Y,8);
g.setColor(Color.black);
g.fillOval(20+X[0],255,80,80);
g.setColor(Color.black);
g.fillOval(170+X[0],255,80,80);
g.drawRect(580,90, 50,100);
g.drawOval(600,100,20,20);
g.drawOval(600,130,20,20);
g.drawOval(600,160,20,20);
if(red){
g.setColor(Color.red);
g.fillOval(600,100,20,20);
}
if(yellow){
g.setColor(Color.yellow);
g.fillOval(600,130,20,20);
}
if(green){
g.setColor(Color.green);
g.fillOval(600,160,20,20);
}
}
}
No comments:
Post a Comment