This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Code: import java.awt.*; public class TestFrame extends Frame { Button firstOne = new Button("One"); Button secondOne = new Button("Two"); public TestFrame() { add(firstOne,BorderLayout.NORTH); add(secondOne,BorderLayout.NORTH); setSize(400,400); setVisible(true); } public static void main(String args[]) { TestFrame tf = new TestFrame(); } } Question: An Attempt to compile and run the above piece of code
A. Causes compilation error - a component cannot be added to region which is already occupied by another component. B. Causes Runtime Exception - a component cannot be added to region which is already occupied by another component. C. Neither A or B. The Frame comes up and only the button with label "Two" occupies the entire North region of the Frame. D. Addition of secondOne causes firstOne to be removed from the container. E. Addition of the secondOne causes the firstOne to be hidden in the container. Answer: C&D. I know that C is correct. But I don't understand why D is correct, not E. I thought method only remove() removes conponents from a container.
Anoop Krishnan
Ranch Hand
Joined: May 03, 2001
Posts: 163
posted
0
Hai Yi, I think that the button 2 replaces the button 1 because you are adding both of them to the same location.That might be what the choice D signifies
I just want to know is there any body call my bean's Getter and Setter methods with "Please" in front - My favorite quip from Bugzilla
yi miao
Greenhorn
Joined: Jun 29, 2001
Posts: 6
posted
0
Hello Anoop, Yes, both of button 2 & button 1 were added to the same location. But my understand is that button 2 is right on the top of button 1, so it hides button 1. If button 1 is removed, remove() method should be invoked.