• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Panel vs Frame

 
Santosh Bapat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
 
Francisco A Guimaraes
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Santosh Bapat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, The book I have implies that they are interchangeable. Thanks for the help.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Panels and Frames are not interchangeable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic