It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes about frame &Layout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "about frame &Layout" Watch "about frame &Layout" New topic
Author

about frame &Layout

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
Question 159)
import java.awt.*;
public class TestFrame extends Frame
{
Button bNorth = new Button("North");
Button bSouth = new Button("South");
Button bEast = new Button("East");
Button bWest = new Button("West");
Button bCenter = new Button("Center");
public TestFrame()
{
setLayout(new FlowLayout());
add(bNorth);
add(bSouth);
add(bWest);
add(bEast);
add(bCenter);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}

Attemping to compile and run the above code

Will cause a compilation error - a Layout cannot be set after a component has been added with a preset Layout Manager.
Will cause a Runtime Exception - a Layout cannot be set after a component has been added with a preset Layout Manager.
Will compile cleanly and throw no runtime Exception. Only the button with label "Center" is visible and occupies the whole screen.
Will compile cleanly an throw no runtime Exception. All the buttons are arranged in a single line. Any other component added in future will follow the rules of the BorderLayout Manager.
Will compile and run cleanly, but no component is visible.
the ans is the 5th. "Will compile and run cleanly, but no component is visible." why???
Jim Hall
Ranch Hand

Joined: Nov 29, 2001
Posts: 162
See
http://www.javaranch.com/ubb/Forum24/HTML/013640.html
wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
thanks Jim . your explanation is very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about frame &Layout
 
Similar Threads
AWT
Layout Qstn
Layout Manager-mock exam
Flow layout
Abhilash #39 - layout managers