Java Reference
In-Depth Information
// repaints the GUI when the state changes
public void run() {
while (alive)
try {
synchronized ( this ) { wait(); }
this .repaint();
this .notifyObservers(eventName);
} catch (InterruptedException ie) {ie.printStackTrace();}
}
}
package parking;
public class PhotoCell extends EventProcess {
public boolean cleared # true ;
// true if the photocell is cleared
String eventName;
public PhotoCell(String name) {
super (name);
}
// sets the state to "OCCUPIED"
public void occupy() {
if (! cleared) return ;
eventName # "OCCUPIED";
cleared # false ;
synchronized ( this ) { notify(); }
}
// sets the state to "CLEARED"
public void clear() {
if (cleared) return ;
eventName # "CLEARED";
cleared # true ;
synchronized ( this ) { notify(); }
}
// repaints the GUI when the state changes
public void run() {
while (alive)
try {
synchronized ( this ) { wait(); }
this .repaint();
this .notifyObservers(eventName);
} catch (InterruptedException ie) {ie.printStackTrace();}
}
}
package parking;
public class TicketDispenser extends EventProcess {
boolean delivered # false ;
// true if the ticket has been delivered
String eventName;
Search WWH ::




Custom Search