2] A) 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(); } } B) 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(); } } first program gives buttons arrnged according to flowLayout but the second one does not display any buttons. Why?
Hima Mangal
Ranch Hand
Joined: Feb 25, 2001
Posts: 82
posted
0
i guess that's because there can be only one layout manager for a container and once u specify a new layout manager over an old one.. the components need to be readded.. guess so...
Hima<BR>Sun Certified Java Programmer
puneet pruthi
Greenhorn
Joined: Feb 10, 2001
Posts: 14
posted
0
Hi shilpa, Abt the layouts,suppose u have initially borderlayout and u have added buttons to it,specifying flow or grid layout ,would override it and the components will b placed acc to the new layout. but if u have flow layout and u give borderlayout afterwards,it wont override ,but give a completely new layoutwhich is blank.It will enclipse the previous layout with the components. Why this happens ,i dont have a clue,i read it some where but no reasons were given.