File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


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

question about awt

kashif sohail
Greenhorn

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();
p.setBackground(Color.white);
this.add(p,BorderLayout.CENTER);// 1
p.add(p2,BorderLayout.CENTER);
}
}
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
Kashif,
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 ...
Enjoy,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question about awt
 
Similar Threads
AWT vs SWING
Scrollbars
Display image in a BorderLayout
Layouts
Dialog Box