Java Reference
In-Depth Information
Figure 22.2. The Door_1 class models a carousel door, relying on state change events
sent by the carousel machine.
The Door_1 class subclasses Observable so that clients, such as a GUI, can observe
a door. The class definition declares its superclass and establishes the states that a door can
enter:
package com.oozinoz.carousel;
public class Door_1 extends Observable
{
public static final int CLOSED = -1;
public static final int OPENING = -2;
public static final int OPEN = -3;
public static final int CLOSING = -4;
public static final int STAYOPEN = -5;
private int state = CLOSED;
//
}
Not surprisingly, a textual description of the state of a door depends on the door's state:
public String status()
{
switch (state)
{
case OPENING :
return "Opening";
case OPEN :
return "Open";
case CLOSING :
return "Closing";
Search WWH ::




Custom Search