0% found this document useful (0 votes)
243 views8 pages

Mini Project On Java: Title:Traffic Signals Using Java Dept: Cse Year: Ii - B

This document describes a Java project on traffic signals. It includes an abstract that discusses using sensors to dynamically control traffic lights based on traffic density. It also describes designing a portable controller for emergency vehicles. The document then provides code for a Java application that simulates a basic traffic light and allows clicking buttons to change the light. It defines classes for the traffic light signals and frame.

Uploaded by

Sudheer Smart
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
243 views8 pages

Mini Project On Java: Title:Traffic Signals Using Java Dept: Cse Year: Ii - B

This document describes a Java project on traffic signals. It includes an abstract that discusses using sensors to dynamically control traffic lights based on traffic density. It also describes designing a portable controller for emergency vehicles. The document then provides code for a Java application that simulates a basic traffic light and allows clicking buttons to change the light. It defines classes for the traffic light signals and frame.

Uploaded by

Sudheer Smart
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

MINI PROJECT ON JAVA

TITLE:TRAFFIC SIGNALS USING JAVA


DEPT : CSE
YEAR : II – B

DONE BY:
SUDHEER KUMAR.N

SUDHEER KUMAR.N CSE 211518104165


TRAFFIC SIGNALS
Abstract:
Traffic light control systems are widely used to monitor and control the flow of
automobiles through the junction of many roads. They aim to realize smooth
motion of cars in the transportation routes. However, the synchronization of
multiple traffic light systems at adjacent intersections is a complicated problem
given the various parameters involved. Conventional systems do not handle
variable flows approaching the junctions. In addition, the mutual interference
between adjacent traffic light systems, the disparity of cars flow with time, the
accidents, the passage of emergency vehicles, and the pedestrian crossing are not
implemented in the existing traffic system. This leads to traffic jam and
congestion. We propose a system based on PIC microcontroller that evaluates the
traffic density using IR sensors and accomplishes dynamic timing slots with
different levels. Moreover, a portable controller device is designed to solve the
problem of emergency vehicles stuck in the overcrowded roads.

Java Design Examples - Traffic Light Simulation


This example is taken from the text book “Java Outside In” by Bolker & Campbell.
It is an example which uses a graphical user interface rather than a text based
interface like that used in the banking program. There are elements in the code
that we have not covered in class, so do not worry if you cannot understand all
that is going on at this stage. What is important is that we follow the object-
oriented nature of the design.

Software Used:
SIDRA INTERSECTION is a powerful software package for timing, capacity,
performance and level of service analysis of signalised intersections (junctions

SUDHEER KUMAR.N CSE 211518104165


controlled by traffic lights) including signal coordination effects. It uses an
advanced critical movement analysis method allowing for overlap movements
and movements with two green periods per cycle. The method was first
published in ARRB Research Report ARR No. 123 by Dr Rahmi Akçelik. "SIDRA"
was first released in 1984 as the software which implemented the ARR 123 signal
capacity and timing analysis methodology.

SUDHEER KUMAR.N CSE 211518104165


PROGRAM:
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);

SUDHEER KUMAR.N CSE 211518104165


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){

SUDHEER KUMAR.N CSE 211518104165


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;

SUDHEER KUMAR.N CSE 211518104165


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());

SUDHEER KUMAR.N CSE 211518104165


if (change){

g.setColor( on );

} else {

g.setColor( on.darker().darker().darker() );

g.fillOval( border,border,2*radius,2*radius );

OUTPUT:

SUDHEER KUMAR.N CSE 211518104165

You might also like