aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Resizing buttons with BorderLayout ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Resizing buttons with BorderLayout ?" Watch "Resizing buttons with BorderLayout ?" New topic
Author

Resizing buttons with BorderLayout ?

joaquim knox
Greenhorn

Joined: Aug 16, 2003
Posts: 9
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.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

I dont know the answer. Are you preparing for scjp 1.2?


Groovy
joaquim knox
Greenhorn

Joined: Aug 16, 2003
Posts: 9
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

Joined: Feb 27, 2002
Posts: 8919

http://www.javaranch.com/certfaq.jsp#q10
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
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 ]

SCJP2. Please Indent your code using UBB Code
joaquim knox
Greenhorn

Joined: Aug 16, 2003
Posts: 9
Thanks so much. I will study your explanation. After reading it only once I still have some questions. What is UBB?
joaquim knox
Greenhorn

Joined: Aug 16, 2003
Posts: 9
Cancel that last question. Right as I hit the Rost Reply I saw the
UBB code directions. Sorry. Robert
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Note that there are NO AWT questions on the 1.4 exam.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Resizing buttons with BorderLayout ?