wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes BorderLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "BorderLayout" Watch "BorderLayout" New topic
Author

BorderLayout

umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
In the code given below, why it is printing button on east? I think that it is printing the button in all direction one by one shows only the last one as only one instence of the Button object is created.Please let me know the correct reason of this output.
public class Q16 extends Applet
{
Button okButton = new Button("Ok");
public void init()
{
setSize(300,300);
setLayout(new BorderLayout());
add(okButton,"North");
add(okButton,"South");
add(okButton,"Center");
add(okButton,"East");
}
}
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

I dont know how to post a link to another post. I asked this same question yesterday. the title of the thread is "Majii exam question 20"


SCJP
Visit my download page
umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
Thanks i went throw your Post, but now my Question is that how it will work, i mean to say is that will it first print it on "North" and then removing it again printing on "South" again removing it and it goes on till the last one is executed. Is it so? as i want to know how the working goes.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

That is how it appears to work to me.
sirisha parimi
Greenhorn

Joined: Dec 18, 2000
Posts: 2
hi,
actually there is one component to be added .so it is added on the last specified location and made visible.
( and for a borderlayout when only one component is added it occupies full and u cann't make out which which side it is added.)

[This message has been edited by sirisha parimi (edited December 19, 2000).]
sunilkumar ssuparasmul
Ranch Hand

Joined: Dec 13, 2000
Posts: 142
i guess umang u r right . i tried it printing System.out.println("some val") after each add method it prints all the four. so it must be putting button in north first and then removing it and putting in subsequent positions. so the last posted is displayed to us.
If i am wrong plz correct

thanks,
sunil.s


"Winners don't do different things<br /> They do things differently"
Baskaran Srinivasan
Greenhorn

Joined: Dec 10, 2000
Posts: 1
Yeah. Looks like it takes the last instance of Button object and prints it in that corresponding location.
But if you create different instances of Button object like
okButton, ok1Button, ok2Button etc.,, and keep adding these
instances across N,S,W,E and Center U will get what u wanted.
Thanks.


<BR>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BorderLayout
 
Similar Threads
layout
SCJP ques on AWT
BorderLayout in Applets
applets
Button trouble