Originally posted by Cristi Tudose:
this is taken from a mock exam:
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.
#Will compile cleanly and throw no runtime Exception. The buttons are arranged as listed below
Button Label Position
CenterCenter
Noerth North
SouthSouth
EastEast
WestWest
Could someone give the explanations for the correct answer provided(#Will compile and run cleanly, but no component is visible).
thanks in advance
Cristi
Originally posted by Cristi Tudose:
this is taken from a mock exam:
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.
#Will compile cleanly and throw no runtime Exception. The buttons are arranged as listed below
Button Label Position
CenterCenter
Noerth North
SouthSouth
EastEast
WestWest
Could someone give the explanations for the correct answer provided(#Will compile and run cleanly, but no component is visible).
thanks in advance
Cristi
Originally posted by atin sehgal:
Hi!
You see it is necessary that the layout manager be associated with the container before any component is added. If we associate the layout manager after the components are added and the container is already made visible, the components appear as if they have been added by the previous layout manager (if none was associated before, then the default). Only subsequent operations (such as resizing) on the container use the new layout manager. But if the container was not made visible before the new layout is added, the components are re-laid out by the new layout manager.
In this case since the componenst have been already laid down and layout has been given.Again implementing layout on the components wd lead to the present scenario..
I wd also suggest u to look at this site and have a look at the study notes of velmurugan(look at chaper 11 on layout Managers)
http://www.geocities.com/velmurugan_p/
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Originally posted by Cristi Tudose:
Atin&Prashant
I admited i'm not study complet this part(AWT) but... i'm a little confused about your arguments.
If you only switch the lines which set the LayoutManager could u tell me what's output.You may compile&run,but please give
me a reson
And if you know( or anybody else) some URLs where the AWT is properly treat give me a sign.
Rgds,Cristi
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
Sun Certified Programmer for Java 2 Platform
Test 094, IBM WID 6.0 cert
SCJP 1.2
SCBCD 1.3 Beta
SCWCD 1.4 Beta
SCMAD Beta
SCDJWS Beta
KS
Always look on the bright side of life. At least this ad is really tiny:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|