Component Events

java.awt.event.ComponentEvent is the superclass of all the events we've discussed so far. It also has a few events of its own that allow you to react when a component is shown, hidden, moved, or resized. These are

  ComponentEvent.COMPONENT_MOVED
  ComponentEvent.COMPONENT_RESIZED
  ComponentEvent.COMPONENT_SHOWN
  ComponentEvent.COMPONENT_HIDDEN
As you might guess, you respond to these events by registering a java.awt.event.ComponentListener with your component. This interface declares four methods:

  public abstract void componentResized(ComponentEvent e)
  public abstract void componentMoved(ComponentEvent e)
  public abstract void componentShown(ComponentEvent e)
  public abstract void componentHidden(ComponentEvent e)
The ComponentEvent class doesn't have any particularly useful methods of its own, but you can use the various methods of the java.awt.Component class to determine where a component was moved or to what size it was resized.


Previous | Next | Top
Last Modified March 16, 1997
Copyright 1997 Elliotte Rusty Harold
elharo@sunsite.unc.edu