• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 37. User Input and Interactivity... > Using Swing Event Listeners

Using Swing Event Listeners

Like their AWT counterparts, Swing event listeners are interfaces. Unlike AWT, Sun hasn't yet implemented many adapter classes, so usually you'll need to override every listener method to implement a listener. To implement an AncestorListener (which has three methods), for example, you might write

public class myAncestorListener implements AncestorListener {
  public void ancestorAdded(AncestorEvent e) {
    // ignore this one
  }
  public void ancestorRemoved(AncestorEvent e) {
    // don't care about this one either
  }
  public void ancestorMoved(AncestorEvent e) {
    // do something in this case
    Here is code to handle the case of a moving ancestor
  }
}
					


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint