• 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

Resizing buttons with BorderLayout ?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I don't understand the following test ?
import java.awt.*;
public class x extends Frame {
public static void main (String {} args ) {
X x = new X();
x.pack();
x.setVisable(true);
}
public X(){
setLayout (new BorderLayout());
Panel p = new Panel();
add(p, BorderLayout.NORTH);
Button b = new Button("NORTH");
p.add(b);
Botton b2 = new Button("SOUTH");
add(b2, BorderLayout.SOUTH);
}
}
Which two statments are true? Shoose Two
A. The buttons labled "North" and "South" will have the same width.
B. The buttons labled "North" and "South" will have the same height.
C. The height of the button labeled "North" can very if the Frame is resized.
D. The height of the button labeled "South" can very if the Frame is resized.
E. The width of the button labeled "North" can very if the Frame is resized.
F. The width of the button labeled "South" can very if the Frame is resized.
Answer:B,E
I don't understand this at all. To me the buttons should have the same width and height.
This also implies that the width of the button labled South CANNOT very if the frame is resized.
Also, I am new here. In a previous post I was told to use some kind of code formater that I didn't understand. I will look into it. Thanks very much.
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know the answer. Are you preparing for scjp 1.2?
 
joaquim knox
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question. What is the difference?
I bought a book, Complete Java 2 Certificatin Study Guide.
It says it is fully updated for J2SE 1.4. Could you tell me a little about each one?
Thanks,R
 
Pradeep bhatt
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://www.javaranch.com/certfaq.jsp#q10
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch joaquim,
In order to understand the LayoutManagers just execute examples like this one and try to understand the behaviour. Before that, Using LayoutManagers from the Java Tutorial might be helpul.
___________________________________________________________________________


_______________________
|=======NORTH===========|
|_______________________|
|W=|==============|==E==|
|E=|==============|==A==|
|S=|====CENTER====|==S==|
|T=|==============|==T==|
|__|______________|_____|
|=======SOUTH===========|
|=======================|
|=======================|
|_______________________|


If you remember the way the components are laid out by a BorderLayout it is easy to deduce how they are going to behave regarding resizing.
Observe that NORTH and SOUTH are given the whole width. That is going to be preserved if the container varies its width, thus NORTH and SOUTH will have their width changing to accomodate the resizing. I have depicted diferent heights for NORTH and SOUTH because BorderLayout honors components' heights.
I think BorderLayout concedes component's preferred height for NORTH and SOUTH. However when changing container's heigth they will not vary.
Observe that WEST and EAST are given the same height. Thus when the container height changes, both heights will accomodate. I think BorderLayout respects preferred witdh for WEST and EAST. They will not change due to resizing.
CENTER component is given the rest of the room, and it will accomodate to any change in container.
________________________________________________________________________
To answer the question apply the explanation above, but there is a trick.
North button is inside a Panel. Thus FlowLayout, not BorderLayout, is responsible for it. Flowlayout centers their components and honors preferred width and height.
Give it a try, post your conclusions and ask for help if you need.
[ September 05, 2003: Message edited by: Jose Botella ]
 
joaquim knox
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much. I will study your explanation. After reading it only once I still have some questions. What is UBB?
 
joaquim knox
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cancel that last question. Right as I hit the Rost Reply I saw the
UBB code directions. Sorry. Robert
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that there are NO AWT questions on the 1.4 exam.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic