my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes AWT related ( GridLayout ) 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 "AWT related ( GridLayout )" Watch "AWT related ( GridLayout )" New topic
Author

AWT related ( GridLayout )

amol re
Ranch Hand

Joined: Mar 21, 2002
Posts: 36
An AWT related question from Mughal book:
Which of these statements are true?
Select all valid answers
a. A grid made by GridLayout must have an equal number of rows and columns.
b. All components in a GridLayout will be square. Their width will be equal to their height.
c. All components in a GridLayout will have the same height.
d. All components in a GridLayout will have the same width.
e. All components within a row of a GridLayout will have the same height.
Answer: c, d, e
What i think should be the answer: b,c,d,e
Arent all components in a GridLayout square??
I have never really worked in AWT so my concepts might not be all that strong. :roll:
Amol
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
I have never really worked in AWT so my concepts might not be all that strong.
Then you should at least try to write a piece of code which shows you that components in GridLayouts are not necessarly square. They all have the same dimensions but they are not square.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Neelima Rao
Greenhorn

Joined: Feb 24, 2002
Posts: 26
The cells in the grid are equal size based on the largest component in the grid, but they dont have to be square.
Tosin Adedoyin
Ranch Hand

Joined: Nov 09, 2001
Posts: 43
hi amol
All the cells in the GridLayout have the same height and width but this does not mean it will be a square . what this means is if the first cell has a height of 5 and width of 1 all the cells will have these same measurement i am placing a code here run and compile and see what the cells looks like i hope this helps
i did not add the event handler
class TT {


public static void main(String args[]) {
Frame t= new Frame();
t.setLayout(new GridLayout (5,1));

for (int i=0;i<10;i++)
{
t.add(new Button("Button" +i));
}



t.setVisible(true);
}
}
J Hreich
Ranch Hand

Joined: Mar 22, 2002
Posts: 37
Hello all,
this is my first time here.
I have to say this is an excellent site with
the best quality posts.
amol,Try the following:
class Testing {
public static void main(String[] args)
{
Frame f = new Frame("hello");
f.setLayout(new GridLayout(2,2));

Panel p = new Panel();
p.add(new Button("1,1"));
f.add(p);

f.add(new Button("1,2"));
f.add(new Button("2,1"));
f.add(new Button("2,2"));

f.setSize(100, 100);
f.setVisible(true);
}
}
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Sir J.H. is my name
Well not here, though
Welcome to Javaranch
Please read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.
amol re
Ranch Hand

Joined: Mar 21, 2002
Posts: 36
Then you should at least try to write a piece of code which shows you that components in GridLayouts are not necessarly square. They all have the same dimensions but they are not square.
yeh..you are absolutely right. i usually prefer doing that. was sitting up late last night, thats why the lethargy , i guess.
and what i stupid question it was!! the uestion reflects my unclear thinking last night. the simple explanation is that if the window to which the gridlayout is applied is itself not square, the individulal cells *CANNOT* be square!!right??
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Just to give you a hard time...
That's not true.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Consider this:

Viewed through the AppletViewer or as an embedded applet with a width of 400 pixels and a height of 300 pixels, the "window" is clearly not a square (of equal pixel numbers in width and height), and yet, using a GridLayout, the components added are displayed using an equal number of pixels vertically and horizontally.
WiLL Tao
Ranch Hand

Joined: Dec 14, 2001
Posts: 56
Originally posted by amol re:
An AWT related question from Mughal book:
Which of these statements are true?
Select all valid answers
a. A grid made by GridLayout must have an equal number of rows and columns.
b. All components in a GridLayout will be square. Their width will be equal to their height.
Amol

i think the answer a equal answer b,
if their width be equal to their height,a grid made by GridLayout must have an equal number of rows and columns.
so they both wrong


Thank Folks who <b>Make Sense</b> here.<br />SCJP Platform 2
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Originally posted by WiLL Tao:
if their width be equal to their height,a grid made by GridLayout must have an equal number of rows and columns.

And I'll give you a hard time also...
See above code snippet which dispells your assumption.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: AWT related ( GridLayout )