This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Event Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Event Handling" Watch "Event Handling" New topic
Author

Event Handling

Vegad Arvind
Ranch Hand

Joined: Jan 10, 2001
Posts: 42
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

Joined: Jan 05, 2001
Posts: 167
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.

Have you tried this Mock Exam Testing Engine yet?<br /><a href="http://www.mycgiserver.com/~nan111/index.html" target="_blank" rel="nofollow">www.mycgiserver.com/~nan111/index.html</a>
Navin Narayan
Greenhorn

Joined: Jan 25, 2001
Posts: 25
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Event Handling
 
Similar Threads
IBM questions
A few doubts
About WindowListener
enableEvents
Events