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 Panel vs Frame 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 "Panel vs Frame" Watch "Panel vs Frame" New topic
Author

Panel vs Frame

Santosh Bapat
Greenhorn

Joined: Mar 13, 2002
Posts: 7
I wrote the following code for practice. The problem is when I substitute "Frame" for "Panel" nothing is displayed. I know that Panel doesn't extend Window so I also comment out the WindowListener, but I can't figure out why I can't create this as a Panel. As always, any guidance would be greatly appreciated.
import java.awt.*;
import java.awt.event.*;
public class license extends Frame{
public static void main(String [] args)
{
Frame p=new Frame();
p.setSize(500,200);
p.setLayout(new BorderLayout());
WindowListener wl=new WindowAdapter(){
public void WindowClosing(WindowEvent e){System.exit(0);}
};
p.addWindowListener(wl);
Button OK=new Button("OK");
TextArea t=new TextArea("By clicking OK, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah\n, blah, blah, blah, blah, blah, blah, blah, blah,\nblah, blah, blah, blah, blah, blah,",5,250);
p.add(BorderLayout.CENTER,t);
p.add(BorderLayout.SOUTH,OK);
p.validate();
p.setVisible(true);
}
}


A sincere thanks to all those who take the time to help others.
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
As far as I know, using only AWT, if you want a window to appear you have to use a Frame. Because of this, you didn�t see nothing when you switched Frame by Panel, because you have to attach the panel to something.
hope it helps,
Francisco


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
Santosh Bapat
Greenhorn

Joined: Mar 13, 2002
Posts: 7
OK, The book I have implies that they are interchangeable. Thanks for the help.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Panels and Frames are not interchangeable.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
 
subject: Panel vs Frame