File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Resizing buttons with BorderLayout ?

 
joaquim knox
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know the answer. Are you preparing for scjp 1.2?
 
joaquim knox
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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: 8927
Firefox Browser Java Spring
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that there are NO AWT questions on the 1.4 exam.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic