Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question about awt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question about awt" Watch "question about awt" New topic

question about awt

kashif sohail

Joined: Dec 04, 2000
Posts: 29
import java.awt.*;
import java.applet.Applet;
public class tcenter extends Applet
public void init(){
setLayout(new BorderLayout());
Panel p2=new Panel();
p2.add(new Button("n"),BorderLayout.NORTH);
p2.add(new Button("s"),BorderLayout.SOUTH);
Panel p =new Panel();
this.add(p,BorderLayout.CENTER);// 1
what is this refer to in line 1 as if i replace it with tcenter it gives me error
2: why the result is like flow layout i.e. two buttons appearing in center not on north and south
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
First you should be aware that both Applet and Panel have FlowLayout as the default. Your code has only changed the Applet (this) to have a BorderLayout. Therefore, your panel p2 of which you are placing your buttons onto has a FlowLayout.
Also your panel P has a FlowLayout also.
To get the correct result you need to create your Panel with the following command:
Panel newPanel = new Panel( new BorderLayout() );
Then your example should give you what you want ...
I agree. Here's the link:
subject: question about awt
It's not a secret anymore!