FileDocCategorySizeDatePackage
CustomControls.javaAPI DocExample3846Wed Aug 08 15:13:48 BST 2001None

CustomControls

public abstract class CustomControls extends JPanel implements Runnable
A convenience class for demos that use Custom Controls. This class sets up the thread for running the custom control. A notifier thread is started as well, a flashing 2x2 rect is drawn in the upper right corner while the custom control thread continues to run.

Fields Summary
protected Thread
thread
protected boolean
doNotifier
private CCNotifierThread
ccnt
private String
name
private static final Color
blue
Constructors Summary
public CustomControls()



       
        setBackground(Color.gray);
        addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                if (thread == null) { start(); } else { stop(); }
            }
        });
    
public CustomControls(String name)

        this();
        this.name = name + " Demo";
    
Methods Summary
public voidpaintComponent(java.awt.Graphics g)

        super.paintComponent(g);
        g.setColor(doNotifier ? blue : Color.gray);
        g.fillRect(getSize().width-2, 0, 2, 2);
    
public voidrun()

 
public voidstart()

        if (thread == null) {
            thread = new Thread(this);
            thread.setPriority(Thread.MIN_PRIORITY);
            thread.setName(name + " ccthread");
            thread.start();
            (ccnt = new CCNotifierThread()).start();
            ccnt.setName(name + " ccthread notifier");
        }
    
public synchronized voidstop()

        if (thread != null) {
            thread.interrupt();
            if (ccnt != null) {
                ccnt.interrupt();
            }
        }
        thread = null;