This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
Consider Paul's rocket mass heater.
 
subject: Panel vs Frame
 
Similar Threads
Awt
Q#16 Marcus Green Layout Managers
beginner's question
Auto Maximise GUI
Help,Components inside my Frame would not be displayed until maximized.