• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

FlowLayout

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can u give the URL to the Quiz.
Thx
 
yanish
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sure, http://www.angelfire.com/or/abhilash/Main.html
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic