15.01.2013 Views

Programs 1 Develop static pages (using Only HTML) of an online ...

Programs 1 Develop static pages (using Only HTML) of an online ...

Programs 1 Develop static pages (using Only HTML) of an online ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5. Create two be<strong>an</strong>s traffic light(only 3 colors –red,green,yellow)<strong>an</strong>d automobile(implemented as a<br />

Textbox which states its state/movement).the state <strong>of</strong> the Automobile should depend on the following<br />

Light Tr<strong>an</strong>sition Table.<br />

Light Tr<strong>an</strong>sition Automobile State<br />

Red ->yellow Ready<br />

TrafficPerson :<br />

package demo;<br />

import java.awt.P<strong>an</strong>el;<br />

import java.awt.event.*;<br />

import java.io.PrintStream;<br />

import java.io.Serializable;<br />

import javax.swing.JTextField;<br />

import java.be<strong>an</strong>s.*;<br />

public class TrafficPerson extends P<strong>an</strong>el<br />

implements Serializable, PropertyCh<strong>an</strong>geListener<br />

{<br />

public TrafficPerson()<br />

{<br />

tx = new JTextField(12);<br />

state="Ready";<br />

tx.setHorizontalAlignment(JTextField.LEFT);<br />

tx.setText("Ready");<br />

tx.setEnabled(false);<br />

add(tx);<br />

}<br />

public void ch<strong>an</strong>ge()<br />

{ if(state.equals("Ready"))<br />

{ state="Move";<br />

tx.setText(state);<br />

}<br />

elseif(state.equals("Move"))<br />

{ state="Stopped";<br />

tx.setText(state);<br />

}<br />

elseif(state.equals("Stopped"))<br />

{<br />

state="Ready";<br />

tx.setText(state);<br />

} }<br />

public void propertyCh<strong>an</strong>ge(PropertyCh<strong>an</strong>geEvent e)<br />

{<br />

ch<strong>an</strong>ge();<br />

}<br />

private JTextField tx;<br />

private String state;<br />

}<br />

21<br />

21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!