CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 1999
    Location
    Sweden
    Posts
    33

    listener classes: When are they called and how?

    Hi
    How do I know when a listeners classes method is called if they have the same argument? If it is somehow automatically how will I know which one is called? Are all called the have the same method?
    I would be very grateful for some help.
    Jen


  2. #2
    Join Date
    Nov 1999
    Location
    Tilburg-Breda, Noord-Brabant, The Netherlands
    Posts
    135

    Re: listener classes: When are they called and how?

    Hi Jen,

    Let's take an example, the WindowListener. It's pretty simple. First of all it's not a class but an Interface.
    Using the interface keyword, Java allows you to fully abstract the interface from its implementation. You can specify a set of methods which can be implemented by one or more classes.

    When an event occurs, the event source invokes the appropiate method defined by the listener and provides an event object as its argument.
    For example the WindowListener defines seven methods to recognize when a window is activated, closed, deactivated, deiconified, iconified, opened, or quit.

    If you implement the WindowListener you should define the following methods:
    void windowActivated(WindowEvent we)
    void windowClosed(WindowEvent we)
    void windowClosing(WindowEvent we)
    void windowDeactivated(WindowEvent we)
    void windowDeiconified(WindowEvent we)
    void windowIconified(WindowEvent we)
    void windowOpened(WindowEvent we)

    In these methods you can define what should happen if this specific event occurs. For example :
    void windowClosing(WindowEvent we) {
    System.exit(0);
    }
    This exits the program if you click on the X (x-icon) on the top right of the window.

    I hope this was usefull for your.

    Greets,
    Jan Meeuwesen
    ( If this answer is of any value to you, rate it! (bottom right in your browser under this text) )


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured