import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

        // A simple on-off display. Used as a visualization of
        // the actions of a Switch class.
class DeviceDisplay extends JPanel {
    public DeviceDisplay(){
        setBorder(new EtchedBorder(EtchedBorder.LOWERED));
        add(getLabel());
        getFrame().addComponent(this);
        // The device should be off initially.
        showOff();
    }

    public void showOn(){
        setBackground(Color.green);
        getLabel().setText("on");
        delay();
    }

    public void showOff(){
        setBackground(Color.yellow);
        getLabel().setText("off");
        delay();
    }

    protected JLabel getLabel(){
        return label;
    }

    private void delay(){
        final int sleepTime = 3000;
        try{
            Thread.sleep(sleepTime);
        }
        catch(Exception e){
        }
    }

    private static ComponentFrame getFrame(){
        return frame;
    }

    private static final int textSize = 20;
    private static final Font font = new Font("SansSerif",Font.BOLD,textSize);
    // Allow space for the longer of the two states off/on.
    private final JLabel label = new JLabel("123",JLabel.CENTER);
    {
             label.setFont(font);
    }
    // The frame shared by all devices displays.
    private static final ComponentFrame frame =
                        new ComponentFrame("On/Off Devices");
}
