Java Reference
In-Depth Information
long delay;
// the duration of a delivering or withdrawing operation
public TicketDispenser(String name) {
super (name);
}
// sets the state to "DELIVERED"
public void deliver() {
if (delivered) return ;
eventName # "DELIVERED";
delay # 700;
delivered # true ;
synchronized ( this ) { notify(); }
}
// sets the state to "WITHDRAWN"
public void withdraw() {
if (! delivered) return ;
eventName # "WITHDRAWN";
delay # 200;
delivered # false ;
synchronized ( this ) { notify(); }
}
// repaints the GUI when the state changes
public void run() {
while (alive)
try {
synchronized ( this ) { wait(); }
thread.sleep(delay);
delivered # ! delivered;
this .repaint();
this .notifyObservers(eventName);
} catch (InterruptedException ie)
{ ie.printStackTrace(); }
}
}
package parking;
public class StoppingBar extends EventProcess {
double angle # 0.0; // 0.0 : horizontal, PI/2 : vertical
double direction # 1.0; // 1.0 : bottom-up, -1.0 : top-down
String eventName;
public StoppingBar(String name) {
super (name);
}
// raises the bar and notifies the "UP" event
public void raise() {
if (angle ## Math.PI / 2.0)
return ;
Search WWH ::




Custom Search