It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About WindowListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About WindowListener" Watch "About WindowListener" New topic

About WindowListener

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 411
This is another Mock Question
Based upon the code below, which of the answers apply?

1. public class TestFrame extends Frame {
2. public TestFrame(String title) {
3. super(title);
4. enableEvents(AWTEvent.WINDOW_EVENT_MASK);
5. }
7. public void
processWindowEvent(WindowEvent we) {
8. System.out.println("Window event processed");
9. }
10. }
a) The window listener that has been added to TestFrame will be called on every window event.

b) This code will compile and run if a window listener is added to an instance of TestFrame.

c) An exception will be thrown if a window listener is added to TestFrame.

d) The window listener that has been added to TestFrame will never get called.

e) This code will not compile if a window listener is added to TestFrame.
According to me correct answer is b I need your expert comments

SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door

Joined: Oct 02, 2000
Posts: 17
you need to call super.processWindowListener() so that the listeners will be notified.
Any doubts refer to RHE it is clear in that.
Herbert Maosa
Ranch Hand

Joined: May 03, 2000
Posts: 289
D is also correct.Any listeners added to this window will never be notified because we have overriden the event delegation method and have not taken care of notifying our listeners.As stated above, a call to super() inside the processWindowEvent() would take care of this.

I agree. Here's the link:
subject: About WindowListener
It's not a secret anymore!