Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About WindowListener

 
Gaurav Chikara
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is another Mock Question
26)
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. }
6.
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
 
sankar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mr.gaurav
you need to call super.processWindowListener() so that the listeners will be notified.
Any doubts refer to RHE it is clear in that.
sankar
 
Herbert Maosa
Ranch Hand
Posts: 289
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hie,
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.

Herbert.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic