• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Q#7 Parikosh's test

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is 2.
What's the "North" and "South" use??
add(new Button("Three"), "North");
add(new Button("Four"), "South");
Thanks.
Q#7 What best describes the appearance of an application with the following code?
import java.awt.*;
public class FlowAp extends Frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
setLayout(new GridLayout());
add(new Panel());
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"), "North");
add(new Button("Four"), "South");
}
}
1) A Frame with buttons marked One to Four placed on a Panel
2) A panel and buttons marked One to four running from the left to right
3) A Frame with one large button marked Four in the Centre
4) An Error at run time indicating you have not set a LayoutManager properly
5) An Error at compile time indicating add is called with invalid parameters.

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jing,

Here u r using layout as GridLayout(),
Gridlayout has constructor as "gridlayout(x,y)"
here x=no. of rows
y = no. of columns
but if you are not passing any arguments to the constructor, it will treat as (1,n)
ie number of components added will be arranged in one row from left to right

Shashank
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree.
The answer should be 2.

------------------

***********************************************
Sun Certified Programmer for Java 2 Platform
***********************************************
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jing,
The 'trick' here is that the Container class provides the add methods that are used by the AWT containers. It is up to each layout if it accepts and uses all the given parameters. In the case you have given, the GridLayout doesn't accept any constraints therefore it chooses to ignore the second parameter in the add() method. It is used to confuse you!
By default a GridLayout creates a single row with many columns. Therefore your result will be 2.
Regards,
Manfred.
 
jing zhao
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I run the program, the 2 is right. In the add() method, it chooses to ignore the second paramter, that confused me.
Thanks all your help.

Originally posted by Manfred Leonhardt:
Hi Jing,
It chooses to ignore the second parameter in the add() method
The 'trick' here is that the Container class provides the add methods that are used by the AWT containers. It is up to each layout if it accepts and uses all the given parameters. In the case you have given, the GridLayout doesn't accept any constraints therefore it chooses to ignore the second parameter in the add() method. It is used to confuse you!
By default a GridLayout creates a single row with many columns. Therefore your result will be 2.
Regards,
Manfred.


 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic