traffic control system using java free download source code
#4

traffic control system using java free download source code

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;

public class TrafficLight extends JFrame implements ActionListener {
JButton b1, b2, b3;

Signal green = new Signal(Color.green);
Signal yellow = new Signal(Color.yellow);
Signal red = new Signal(Color.red);

public TrafficLight(){
super("Traffic Light");
getContentPane().setLayout(new GridLayout(2, 1));
b1 = new JButton("Red");
b2 = new JButton("Yellow");
b3 = new JButton("Green");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);

green.turnOn(false);
yellow.turnOn(false);
red.turnOn(true);

JPanel p1 = new JPanel(new GridLayout(3,1));
p1.add(red);
p1.add(yellow);
p1.add(green);
JPanel p2 = new JPanel(new FlowLayout());
p2.add(b1);
p2.add(b2);
p2.add(b3);

getContentPane().add(p1);
getContentPane().add(p2);
pack();
}


public static void main(String[] args){
TrafficLight tl = new TrafficLight();
tl.setVisible(true);
}
public void actionPerformed(ActionEvent e){
if (e.getSource() == b1){
green.turnOn(false);
yellow.turnOn(false);
red.turnOn(true);
} else if (e.getSource() == b2){
yellow.turnOn(true);
green.turnOn(false);
red.turnOn(false);
} else if (e.getSource() == b3){
red.turnOn(false);
yellow.turnOn(false);
green.turnOn(true);
}
}
}
class Signal extends JPanel{

Color on;
int radius = 40;
int border = 10;
boolean change;

Signal(Color color){
on = color;
change = true;
}

public void turnOn(boolean a){
change = a;
repaint();
}

public Dimension getPreferredSize(){
int size = (radius+border)*2;
return new Dimension( size, size );
}

public void paintComponent(Graphics g){
g.setColor( Color.black );
g.fillRect(0,0,getWidth(),getHeight());

if (change){
g.setColor( on );
} else {
g.setColor( on.darker().darker().darker() );
}
g.fillOval( border,border,2*radius,2*radius );
}
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Tagged Pages: source code for design a traffic controller systems with java, automatic traffic control system java, traffic management system in java code, traffic control system project in java, traffic system application java code, traffic control java source code, program in java for automatic trafic control,
Popular Searches: java code for traffic control system, traffic management system source code in java, java source code that controls traffic lightsphoto compression, source code project on traffic mgmt system, traffic control system using java, java source code for traffic control project, traffic system application java code,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Messages In This Thread
RE: traffic control system using java free download source code - by seminar report asees - 15-10-2015, 02:13 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
Music download free atm with an eye documentation and ppts 5 19,059 27-02-2019, 10:14 AM
Last Post:
  free download college alumni project in php 6 19,626 02-12-2018, 07:06 PM
Last Post:
  solution manual of cl wadhwa power system pdf free download 8 23,509 25-11-2018, 10:48 PM
Last Post:
  technical dumb charades free download related to electrical engineering 1 20,473 18-08-2018, 04:14 PM
Last Post: Guest
Big Grin public distribution system project in vb net pdf download 1 20,320 14-08-2018, 07:25 PM
Last Post: Guest
  free download source code of online college magazine 5 17,878 29-06-2018, 10:09 AM
Last Post: Guest
  mobile computing rajkamal pdf free download 3 18,673 15-06-2018, 07:35 PM
Last Post: susithra baskaran
  download of embedded system black book by kvkk prasad 1 1,949 08-06-2018, 07:52 AM
Last Post: silpa navuluri
  opengl source code for butterfly 3 3,276 14-05-2018, 08:57 AM
Last Post: Akshatha k
  program code of solar tracking system using 8051 microcontroller 6 23,385 03-05-2018, 09:30 PM
Last Post: Guest

Forum Jump: