File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes FlowLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "FlowLayout" Watch "FlowLayout" New topic
Author

FlowLayout

yanish
Greenhorn

Joined: Aug 18, 2000
Posts: 21
Exam on the rbHilash's Java Quiz site:
Question 42

import java.awt.*;
public class TestFrame extends Frame
{
public TestFrame()
{
Button one = new Button("One");
Button two = new Button("Two");
Button three = new Button("Three");
setLayout(new FlowLayout());
add(one);
add(two);
add(three);
two.setVisible(false);
setSize(1000,1000);
setVisible(true);
validate();
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
1) If the above code runs, the buttons - one and three are laid out in a single row from left to right with a gap in between .
2) If the above code runs, the buttons - one and three are laid out in a single row from left to right with no gap in between.
3) Code does not compile - a component can not be hidden after being added to a container.
4) Code gets compiled successfully but throws runtime Exception - a component can not be hidden after being added to a container
the given answer is 2), but I'm not sure. Default constructor of the FlowLayout sets the horizontal gap to 5. So, the gap between the buttons 'one' and 'three' will be 5. Am I right?
Aru
Ranch Hand

Joined: Jul 20, 2000
Posts: 112
Can u give the URL to the Quiz.
Thx
yanish
Greenhorn

Joined: Aug 18, 2000
Posts: 21
sure, http://www.angelfire.com/or/abhilash/Main.html
mehrar
Greenhorn

Joined: Aug 16, 2000
Posts: 19
Originally posted by yanish:
Exam on the rbHilash's Java Quiz site:
Question 42

import java.awt.*;
public class TestFrame extends Frame
{
public TestFrame()
{
Button one = new Button("One");
Button two = new Button("Two");
Button three = new Button("Three");
setLayout(new FlowLayout());
add(one);
add(two);
add(three);
two.setVisible(false);
setSize(1000,1000);
setVisible(true);
validate();
}
public static void main(String args[])
{
TestFrame tf = new TestFrame();
}
}
1) If the above code runs, the buttons - one and three are laid out in a single row from left to right with a gap in between .
2) If the above code runs, the buttons - one and three are laid out in a single row from left to right with no gap in between.
3) Code does not compile - a component can not be hidden after being added to a container.
4) Code gets compiled successfully but throws runtime Exception - a component can not be hidden after being added to a container
the given answer is 2), but I'm not sure. Default constructor of the FlowLayout sets the horizontal gap to 5. So, the gap between the buttons 'one' and 'three' will be 5. Am I right?


You are right. The default Horizontal Gap and Vertical Gap is 5 if you do not specify it(and is not specified in this constructor call). The correct answer will be 1 with a default gap specified instead of a gap. Also instead of calling this contructor you can use the other constructor:-
public FlowLayout(int align, int hgap, int vgap) and specify the gaps there. In case you do not specify the gaps in this constructor you'll still get the default gaps of 5 in between the components.

------------------
Raj


Raj
Harry Chawla
Ranch Hand

Joined: Jun 03, 2000
Posts: 97
I believ what the question writer meant by with gap is that will there be a gap for button two - which is setVisible(false)
I agree that because of the default spacing, the answers area bit confusing.
Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: FlowLayout