• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

layout's

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

Please pick up the right answer and explain the reason for choosing that answer.
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The GridLayout() constructor creates a grid layout with a default of one column per component, in a single row .
Hence panel and buttons marked One to four running from the left to right are displayed which is answer choice 2.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nitin,
The answer to your question is (2). The reason is that
when you set the layout with <code> setLayout(new GridLayout());</code> you changed the default LayoutManager
of Frame which is BorderLayout. Now, the Layout was made with
<code>zero parameter</code> so it creates a grid layout with a default of one column per component, in a single row.
Thereafter, you added five components viz., panel, button "one" , button "two", button "three", button "four". These components
would be laid out in a row, left to right.
As far choice (5) goes, please refer the API , Frame class inherits the <code> add( ) </code> of the <code> java.awt.Container
class </code>
.
Hope this clarifies your querry.
Cheers,
Ravindra Mohan.


[This message has been edited by Ravindra Mohan (edited May 04, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic