FileDocCategorySizeDatePackage
ComponentEventDemo.javaAPI DocExample4083Tue Dec 12 18:58:54 GMT 2000None

ComponentEventDemo

public class ComponentEventDemo extends JApplet implements ComponentListener, ActionListener

Fields Summary
JTextArea
display
JFrame
aFrame
public boolean
showIt
static final String
SHOW
static final String
CLEAR
String
newline
Constructors Summary
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent e)

        if (e.getActionCommand() == SHOW) {
            showIt = true;
            aFrame.setVisible(true);
        } else { //CLEAR
            display.setText("");
        }
    
public voidcomponentHidden(java.awt.event.ComponentEvent e)

        displayMessage("componentHidden event from "
                       + e.getComponent().getClass().getName());
    
public voidcomponentMoved(java.awt.event.ComponentEvent e)

        displayMessage("componentMoved event from "
                       + e.getComponent().getClass().getName());
    
public voidcomponentResized(java.awt.event.ComponentEvent e)

        displayMessage("componentResized event from "
                       + e.getComponent().getClass().getName());
    
public voidcomponentShown(java.awt.event.ComponentEvent e)

        displayMessage("componentShown event from "
                       + e.getComponent().getClass().getName());
    
protected voiddisplayMessage(java.lang.String message)

        display.append(message + newline);
    
public voidinit()


       
        display = new JTextArea();
        display.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(display);
        scrollPane.setPreferredSize(new Dimension(200, 75));
        getContentPane().add(scrollPane, BorderLayout.CENTER);

        JButton b1 = new JButton("Start playing...");
        b1.setActionCommand(SHOW);
        b1.addActionListener(this);
        getContentPane().add(b1, BorderLayout.NORTH);

        JButton b2 = new JButton("Clear");
        b2.setActionCommand(CLEAR);
        b2.addActionListener(this);
        getContentPane().add(b2, BorderLayout.SOUTH);

        aFrame = new JFrame("A Frame");
        ComponentPanel p = new ComponentPanel(this);
        aFrame.addComponentListener(this);
        p.addComponentListener(this);
        aFrame.getContentPane().add(p, BorderLayout.CENTER);
        aFrame.pack();

        aFrame.addWindowListener(new WindowAdapter() {
            // This event handler is executed before the
            // default close operation (hide) is applied.
            public void windowClosing(WindowEvent e) {
                showIt = false;
            }
        });
    
public voidstart()

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if (showIt) {
                    aFrame.setVisible(true);
                }
            }
        });
    
public voidstop()

        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                aFrame.setVisible(false);
            }
        });