This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Which of the following statements about information you get from MouseEvent events that come to these listeners are correct? 1.The getX() and getY() methods return the position of the event relative to the Panel. 2.The getX() and getY() methods return the position of the event relative to the Frame. Correct Ans:1 b'coz positions are relative to the component that generates the event. My Doubt: Why can't the same logic be applied to the 2. option that is Frame.Afterall even Frame is a component.According to me both the answers are correct. Please clarify. Regards, Kavita.
Hi Kavita, I think the answer relates to what source the MouseEvent is coming from. If we have set the Panel to be the MouseEvent listener then 1 would be correct. If we set the Frame to be the MouseEvent listener then 2 would be correct. The layout here is also important. If we place a Panel into a Frame, the panel will end up in the BorderLayout.CENTER position of the frame which will in effect take up the entire Frame. Therefore, the frame as a mouse listener will never get any events because the Panel is in front of it! This is probably the logic being used by the tester. Regards, Manfred.
Joined: Oct 10, 2000
Hi Manfread, YES.U are right here the layout and on what component the event takes place is important.But how can we make assumptions?How can u assume that Panel is the source of event and not Frame.And again if such questions appear in the exam then what will be the correct answer. Thanks for your prompt reply. Regards, Kavita.
Joined: Jan 09, 2001
Hi Kavita, The exam questions won't be ambiguous and you won't need to assume anything! Don't equate mock exams with the real thing. Most mock exams are just created in spare time. The real exam has been created and developed making sure that all questions are straight forward and correctly worded to avoid any problems. If you continue down this path you will work yourself into a failing grade without even taking the exam! If you understand the concepts thoroughly then you will have no problems with the real exam. Regards, Manfred.