Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

border layout (MUGHAL) pls hlp !!!!

 
kaushik banerjee
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
this is a piece of code taken from khalid.it compiles & runs fine. what is escaping me is that can i add the constraints in the manner shown without paying heed to the case of the constraints . i had the notion that constraints could only be added as for example in this fashion-- BorderLayout.SOUTH . if not,will any case combination of the constraint constants work . also i believe that the constants NORTH,SOUTH,EAST,WEST,CENTER were static & one had to use either the class name or the object name with them . what do u guys say?
import java.awt.*;
public class MyFrame
{
public static void main(String[] a)
{
Window w = new Frame();
String[] s={"North","South","East","West","Center"};
for(int i=0;i<s.length;i++)>
w.add(new Button(s[i]),s[i]);
w.pack();
w.setSize(250,250);
w.setVisible(true);
}
}
THX IN ADVANCE
Regards,
KAUSHIK
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kaushik,
The case is VERY important. The BorderLayout happens to check for the strings:
North, South, Center, West, and East
If you use any other case (i.e., NORTH, north, NOrth, etc.) you will not get the desired result. If the string is not matched then Center is assumed!
Final static variables are also defined in BorderLayout and as Java convention are capitalized:
BorderLayout.NORTH
BorderLayout.SOUTH
BorderLayout.CENTER
BorderLayout.WEST
BorderLayout.EAST
Regards,
Manfred.
 
shadow liu
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
These are some old method which should be replaced with 1.1 method.
From Class Container Doc:
********
public Component add(String name, Component comp)
Adds the specified component to this container. It is strongly advised to use the 1.1 method, add(Component, Object), in place of this method.

public void add(Component comp,Object constraints)
Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this container's layout using the specified constraints object.
*******
HTH.

[This message has been edited by shadow liu (edited April 24, 2001).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic