Share on Google+Share on Google+

Pari Kapoor
java program to create animated traffic signal
2 Answer(s)      5 years and 7 months ago
Posted in : Java Beginners

a java program to create animated traffic signal (use 5 seconds to blink each light one after the other) using multithreading.

Ads

View Answers

September 7, 2011 at 12:58 PM


import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class traffic extends Applet implements Runnable{
Thread t;
Font f,f1;
int i=0,a=0,j=0;
public void init(){

setBackground(Color.lightGray);
f=new Font("TimesNewRoman",f.ITALIC,28);
f1=new Font("TimesNewRoman",Font.ITALIC+Font.BOLD,28);
}
public void start() {
t=new Thread(this);
t.start();
}
 public void run(){
  for(i=25;i>=0;i--){
   try {
Thread.sleep(5000);
}
catch(Exception e){
System.out.println(e);
}
if(i<=25 && i>3){
a=1;
repaint();
}
else
if(i<=3 && i>0){
a=2;
repaint();
}
else
if(i==0){
for(j=0;j<25;j++){
a=3;
try {
Thread.sleep(5000);
}
catch(Exception e){
System.out.println(e);
}
  repaint();
}
 if(j==25){
run();
}
  }
  }
 repaint();
}


September 7, 2011 at 1:00 PM


continue..

 public void paint(Graphics g) {
setBackground(Color.lightGray);
g.setColor(Color.black);
g.fillArc(100,150,100,100,0,180);
g.drawArc(100,150,100,100,0,180);

g.setColor(Color.black);
g.fillRect(150,150,50,150);
g.drawRect(150,150,50,150);

g.setColor(Color.black);
g.fillRect(165,300,20,155);
g.drawRect(165,300,20,155);

g.drawOval(150,150,50,50);
g.drawOval(150,200,50,50);
g.drawOval(150,250,50,50);

g.setColor(Color.red);
g.setFont(f);
g.drawString(""+i,50,50);

g.setColor(Color.white);
g.fillRect(300,5,15,125);
g.drawRect(300,5,15,125);

g.setColor(Color.white);
g.fillRect(300,145,15,135);
g.drawRect(300,145,15,135);

 g.setColor(Color.white);
g.fillRect(300,300,15,135);
g.drawRect(300,300,15,135);

g.setColor(Color.white);
g.fillRect(450,5,15,125);
g.drawRect(450,5,15,125);

g.setColor(Color.white);
g.fillRect(450,145,15,135);
g.drawRect(450,145,15,135);

g.setColor(Color.white);
g.fillRect(450,300,15,135);
g.drawRect(450,300,15,135);

g.setColor(Color.black);
g.fillRect(600,300,15,135);
g.drawRect(600,300,15,135);

g.setColor(Color.green);
g.fillArc(560,290,100,100,0,180);
g.drawArc(560,290,100,100,0,180);

g.setColor(Color.black);
g.fillRect(460,300,15,135);
g.drawRect(460,300,15,135);

g.setColor(Color.green);
g.fillArc(420,290,100,100,0,180);
g.drawArc(420,290,100,100,0,180);

if(a==1){
g.setColor(Color.red);
g.fillOval(150,150,50,50);
g.drawOval(150,150,50,50);
g.drawString("STOP",50,150);
}
if(a==2){
g.setColor(Color.yellow);
g.fillOval(150,200,50,50);
g.drawOval(150,200,50,50);
g.drawString("READY",50,200);
}
if(a==3){
g.setColor(Color.blue);
g.setFont(f);
g.drawString(""+j,150,50);

g.setColor(Color.green);
g.fillOval(150,250,50,50);
g.drawOval(150,250,50,50);
g.drawString("GO",50,250);
 }
int x1[]={220,300,300,280};
int y1[]={250,150,250,150};
int n1=4;
int n2=3;
int x2[]={340,380,380};
int y2[]={150,100,150};
int x3[]={460,460,500};
int y3[]={150,100,150};

g.setColor(Color.black);
g.fillPolygon(x1,y1,n1);
g.drawPolygon(x1,y1,n1);
g.setColor(Color.yellow);
g.fillRect(380,100,80,50);
g.drawRect(380,100,80,50);

g.setColor(Color.yellow);
g.fillPolygon(x2,y2,n2);
g.drawPolygon(x2,y2,n2);

g.setColor(Color.yellow);
g.fillPolygon(x3,y3,n2);
g.drawPolygon(x3,y3,n2);

g.setColor(Color.black);
g.fillOval(440,210,60,60);
g.drawOval(440,210,60,60);

g.setColor(Color.black);
g.fillOval(340,210,60,60);
g.drawOval(340,210,60,60);

g.setColor(Color.red);
g.fillRect(300,150,250,100);
g.drawRect(300,150,250,100);

g.setColor(Color.black);
g.setFont(f1);
g.drawString ("Zumbo",380,200);
 }
}









Related Tutorials/Questions & Answers:
How to design animated traffic lights
How to design animated traffic lights You would have seen an animated traffic light on the road, I am interested with this so I have decided to design it. You can also make it by using this interesting example so
How to Create Animated Main Menu Application with Java Swnig Buttons - Java Beginners
How to Create Animated Main Menu Application with Java Swnig Buttons  Hello sir I want to display Main Menu after Log in i have created Log in Form but I want More attractive Animated Main Menu which includes Following
Advertisements
how to make traffic light code in java
how to make traffic light code in java  what is code of traffic light in java
How to create first program in Java?
How to create first program in Java?  Hi, I am new in Java programming. Tell me How to create first program in Java? Thanks   Hi, Read more at First Java Program. Thanks
coding for eletric signal graph
coding for eletric signal graph  How can I draw an electric signal from Manchester and Differential Manchester coding from binary bits that converted from a character for example character
java program - Java Beginners
java program  1.write a program to show traffic signal using multithreading. 2.Except an integer from 1-12 and display corresponding month. if the integer is not between 1-12 then give the errer message and promit
create and use an array variable in a java program
create and use an array variable in a java program  how do i write a program that will prompt the user for a list of 5 prices, once the user has entered all values , your program should compute and display the following: The sum
Create a java program using Java with LinkedLists
Create a java program using Java with LinkedLists  Assignment is -- Question For this part of the assignment, you will develop a Java application... that reverses the list in place (that is, does not create a new copy of the list) Step 2
Traffic Simulator
Traffic Simulator  Hi, I am doing a project on creating a traffic simulator for a particular road junction in java. I am looking for ideas on how I would go about recreating the visual of the junction in which I can have moving
How to create the program in Java for getting the forgotten Password Form?
How to create the program in Java for getting the forgotten Password Form? ... to the user on email address. How to create the program in Java for getting the forgotten Password Form? Thanks   For this you should create a form
program to create nested tables
program to create nested tables  program to create nested tables
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
Create a Program that Calculates Input
Create a Program that Calculates Input   Create a program that takes user input and does a calculation with it, then prints the results back.... For top points, provide options and make the program pretty. (ASCII art &
program to create node.
program to create node.  Hi i'm new to flex and trying to create a node and it should also have an option of right click wit any properties. how do i do this. Also i need to create a gui having drag and dop options. Please help
Increase Web Traffic,How to Increase Web Traffic,Increase Website Traffic,Free Tips to Increase Website Traffic
How to Increase Web Traffic This tutorial will help you increase your website traffic. Today website success depends on the steady flow of the web traffic... adwords program. But if you don't have money or you don't want to spend money
create a jsp program
create a jsp program  please help , create web Application using jsp and jdbc which tacking your name,id and DOB .On clicking to submit Button it stores the information into the database and Displays alll the records
html program to create home page
html program to create home page  html program to create home page
uiscrollview setcontentoffset animated
uiscrollview setcontentoffset animated  Hi, What is actual code to call uiscrollview setcontentoffset animated method? Thanks   Hi, Here is the code: [myScrollView setContentOffset:CGPointMake(0.0f, 0.0f)]; Thanks
Java program to create a frame with 4 fields;name,sreet,city,pin;with suitable table
Java program to create a frame with 4 fields;name,sreet,city,pin;with suitable table  Java program to create a frame with 4 fields;name,street,city,pin;with suitable table. Also add a button "OK". whe it is clicked
program to create student report using java applet,read the input using text boxesand generate the grades..?
program to create student report using java applet,read the input using text boxesand generate the grades..?   sir plz give me java applet codes for above question
how to create classes for lift program
how to create classes for lift program  i would like to know creating classes for lift program
To write a Java program To create a frame with 4 fields;name,street,city,pin;with suitable table
To write a Java program To create a frame with 4 fields;name,street,city,pin;with suitable table  I want to write a Java program To create... to be appeared in text field Can someone write a program for the above? I have
How to make an animated blast, make an animated blast, animated blast
How to make an animated blast       Now get ready to learn a easy methods to learn an animated blast. New File: Take a new file with black background. Make a Bomb
How to design a animated signature, design a animated signature, animated signature
How to design an animated signature       This is very interesting example because you all will learn how to make an animated signature example. It has some easy instruction
write a program to create a user defined
write a program to create a user defined   plz send me code   Hi Friend, Please specify what do you want to create? Thanks
How to make an animated heart, animated heart, heart
How to make an animated heart       Here, I have make an animated heart effect by using the simple processor that is mentioned in this example to learn this effect
How to design an animated banner, design an animated banner, animated banner
How to design an animated banner       Learn a simple way to make an animated banner that is used in the website to show advertisement. New File: Take a new document
code for traffic control system simulation
code for traffic control system simulation  any one suggest which functions are used to develop a graphical view to traffic control system using awt and swing
what's the logic for create pattern program
what's the logic for create pattern program   1 2 3 4 5 5 1 2 3 4 4 5 1 2 3 3 4 5 1 2 2 3 4 5 1
Factors responsible for GPS signal errors
Factors responsible for GPS signal errors   ..., the orbital position of the satellite and a measurement of signal delay. Calculating... the signal delay, the receiver prepares an identical sequence of the Coarse
How to Track Website Traffic?
whatever to roll a great SEO campaign everything boils down to your website traffic that actually translates into your website revenue. Thus to track website traffic... traffic and measuring various qualitative attributes is important for your web
Tutorials   
Java Spring Hibernate Struts Training What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized how to convert war file into .exe file using java code

Ads

 
Advertisement null

Ads