Abilash's mock exam Q39 has me confused. After Q38 I thought I had a decent idea of what was going on. But why doesn't any button appear when you construct a frame with this 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 BorderLayout());
add(bSouth,BorderLayout.SOUTH);
add(bWest,BorderLayout.WEST);
add(bEast,BorderLayout.EAST);
add(bNorth,BorderLayout.NORTH);
add(bCenter);
setLayout(new FlowLayout());
validate();
pack();
setVisible(true);
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
I thought it would display a single button - the last one added - in the center of the frame, occupying the entire frame. But it doesn't. I obviously dont understand how and when doLayout() is called and components are laid out.
It is tough finding information on AWT. Can someone please give me some info/pointers?
[ May 12, 2002: Message edited by: R Arun ]
[ May 12, 2002: Message edited by: R Arun ]