Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Event Handling

 
Vegad Arvind
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Que from IBM moc
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.


Multiple Select - Please select all of the correct answers (this question has 2 correct choices).

can anybody pls. explain.
Thanks
Avi
 
nan sh
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To use enableEents(AWTEvent.WINDOW_EVENT_MASK),
you must call super.precessWindowEvent(e),
otherwise actinPerformed() never
will be called, so line 7-9 should be;
7. public void processWindowEvent(WindowEvent we) {
8. System.out.println("Window event processed");
9. super.precessWindowEvent(we)
10. }
So that d) is the answer, and b) is correct too,
as you can have more then one Window listener.
see R&H book p354 for more details.
correct me, if i am wrong.
 
Navin Narayan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi nan,
You are right except for this we are
"To use enableEvents(AWTEvent.WINDOW_EVENT_MASK),
you must call super.precessWindowEvent(e),
otherwise actinPerformed() never will be called"
It is not to use enableEvents(AWTEvent.WINDOW_EVENT_MASK)
that we call super.precessWindowEvent(e), but only to invoke the super class's method which informs all the registered listeners about the event and calls their actionPerformed(e).
Regards,
Navin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic