Hi,
code #1 returns no component on the frame. However, code #2 returns a list of button in a row. Can anyone explain to me why? My thought is that code #1 will return one big button C at the center of the frame because when you add an element in borderLayout w/o specifying the location, it would add the button to center.
Thank you very much.
#1
class TestFrame extends Frame
{
Button bN = new Button("N");
Button bS = new Button("S");
Button bE = new Button("E");
Button bW = new Button("W");
Button bC = new Button("C");
public TestFrame()
{
setLayout(new FlowLayout());
add(bN);
add(bS);
add(bW);
add(bE);
add(bC);
setLayout(new BorderLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
TestFrame tf = new TestFrame();
}
}
#2
class TestFrame extends Frame
{
Button bN = new Button("N");
Button bS = new Button("S");
Button bE = new Button("E");
Button bW = new Button("W");
Button bC = new Button("C");
public TestFrame()
{
setLayout(new BorderLayout());
add(bN, BorderLayout.NORTH);
add(bS, BorderLayout.SOUTH);
add(bW, BorderLayout.WEST);
add(bE, BorderLayout.EAST);
add(bC, BorderLayout.CENTER);
setLayout(new FlowLayout());
validate();
setSize(300,300);
setVisible(true);
}
public static void main(String[] args)
{
TestFrame tf = new TestFrame();
}
}