• 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

Layout, mock question

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. import java.awt.*;
2.
3. public class Q4 extends Frame {
4. Q4( ) {
5. // use Grid layout manager.
6. setSize(300,300);
7. setLayout(new GridLayout(3,1));
8.
9. // Build and add 1st panel.
10. Panel p1 = new Panel( );
11. p1.setLayout(new BorderLayout( ) );
12. p1.add(new Button("Alpha"),BorderLayout.NORTH );
13. add( p1 );
14.
15. // Build and add 2nd panel.
16. Panel p2 = new Panel( );
17. p2.setLayout(new BorderLayout( ) );
18. p2.add(new Button("Beta"), BorderLayout.CENTER);
19. add(p2);
20.
21. // Build and add 3rd panel.
22. Panel p3 = new Panel( );
23. p3.setLayout( new BorderLayout( ) );
24. p3.add(new Button("Gamma"),BorderLayout.SOUTH);
25. add(p3);
26. }
27.
28. public static void main(String args[ ] ) {
29. Q4 that = new Q4( );
30. that.setVisible(true);
31. }
32. }

A. Each button is as wide as the frame and is just tall enough to encompass its label. The "Alpha" button is at the top of the frame. The "Beta" button is in the middle. The "Gamma" button is at the bottom.

B. Each button is as wide as the frame. The "Alpha" button is at the top of the frame and is just tall enough to encompass its label. The "Beta" button is in the middle of the frame;
its height is approximately 1/3 the height of the frame. The "Gamma" button is at the bottom of the frame and is just tall enough to encompass its label.

C. Each button is just wide enough and just tall enough to encompass its label. All three buttons are Centered Horizontally. The "Alpha" button is at the top of the frame. The "Beta" button is in the middle. The "Gamma" button is at the bottom.

D. Each button is just wide enough to encompass it's label. All three buttons are centered horizontally. The "Alpha" button is at the top of the frame and is just tall enough to encompass its label. The "Beta" button is in the middle of the frame; its heightis approximately 1/3 the height of the frame. The "Gamma" button is at the bottom of the frame and is just tall enough
to encompass its label.

E. Each button is as tall as the frame and is just wide enough to encompass its label. The "Alpha" button is at the left of the frame. The "Beta" button is in the middle. The "Gamma" button is at the right.
//I LIKEED D, BUT ITS NOT THE RIGHT ANSWER, HOW COME ?
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The three panels are using BorderLayout. North and south for this layout are always the width of the screen and since there's no components at east or west in the example the component at the center position also extends the width of the screen.
 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so what is the correct answer ??? B???
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is taken from API Doc :
"The GridLayout class is a layout manager that lays out a container's components in a rectangular grid.
The container is divided into equal-sized rectangles, and one component is placed in each rectangle."
(*)GridLayout ignores the component preffered size
So you have 3 equal region in which you put 3 panel(uses BorderLayout)
In my opinion,the answer that match best is B(D in false bcos of (*))
Rgds,
cristi
 
Or we might never have existed at all. Freaky. So we should cherish everything. Even this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic