Java Reference
In-Depth Information
Observer
GUIFrame
GUIMessages
GUIParkingArea
update()
main()
Car
TrafficLight
PhotoCell
Dispenser
StoppingBar
Controller
setGreen()
setRed()
run()
occupy()
clear()
run()
deliver()
withdraw()
run()
raise()
lower()
run()
run()
run()
Figure 11.9
The GUI classes
the value of the state variable and wake up the thread. The
run()
method
notifies state transitions.
package
parking;
public class
TrafficLight
extends
EventProcess {
public boolean
stop
#
false
;
// true if the light is red, false if green
String eventName;
// the name of an event that will be broadcast
public
TrafficLight(String name) {
super
(name);
}
// sets the state to "RED", if it is "GREEN";
// then it notifies the thread
public void
setRed() {
if
(stop)
return
;
eventName
#
"RED";
stop
#
true
;
synchronized
(
this
) { notify(); }
}
// sets the state to "GREEN", if it is "RED";
// then it notifies the thread
public void
setGreen() {
if
(!stop)
return
;
eventName
#
"GREEN";
stop
#
false
;
synchronized
(
this
) { notify(); }
}