Component Listeners

Component Shown
Component Hidden
Component Moved
Component Resized

Applet :     On clicking “SHOW” Button, a Component Frame appears on the screen and simultaneously word “Shown” is displayed in the TextArea. On moving or resizing Frame Component, the word “Moved” or “Resized” appear in the TextArea. On clicking “HIDDEN” Button, Frame Component disappear and word “Hidden” is displayed in TextArea.

 
 import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class FrameComponent extends Applet implements ActionListener,ComponentListener
{
    Frame f1;
    TextArea ta1;
    Button b1, b2;
    public void init()
{
        f1 = new Frame("Frame With Component");
        ta1 = new TextArea(20,20);
        b1 = new Button("Show");
        b2 = new Button("Hide");

        add(b1);
        add(b2);
        add(ta1);
      
        b1.addActionListener(this);
        b2.addActionListener(this);
        f1.addComponentListener(this);
    }
    public void actionPerformed(ActionEvent e)
    {
        if(e.getSource() == b1)
        {
            f1.setVisible(true);
        }
        else
        if(e.getSource() == b2)
        {
            f1.setVisible(false);
        }
    }
    public void componentShown(ComponentEvent e1)
    {
        ta1.append("Shown\n");
    }
    public void componentHidden(ComponentEvent e1)
    {
        ta1.append("Hidden\n");
    }
    public void componentMoved(ComponentEvent e1)
    {
        ta1.append("Moved\n");
    }
    public void componentResized(ComponentEvent e1)
    {
        ta1.append("Resized\n");
    }
}

Click new -> File -> html    and save this file as FrameComponent.html

<BODY>

<Applet code=FrameComponent.class height=100 width=400 >

</Applet>

</BODY>