Hello every1,
here is the code
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
1. Will cause a compilation error - a Layout cannot be set after a component
has been added with a preset Layout Manager.
2. Will cause a Runtime Exception - a Layout cannot be set after a component
has been added with a preset Layout Manager.
3. Will compile cleanly and throw no runtime Exception. Only the button with
label "Center" is visible and occupies the whole screen.
4. 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.
5. Will compile and run cleanly, but no component is visible.
Answer is 5:
But when i use BorderLayout in case of flow layout in case1 and changing all the five buttons added to different location of BorderLayout, and then changing the layout to flowLayout. Doing this it is showing the buttons in a row ie in FlowLayout, then why it is not showing other way round.