GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes uncleared panel topic Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "uncleared panel topic" Watch "uncleared panel topic" New topic
Author

uncleared panel topic

khan ali
Greenhorn

Joined: Nov 22, 2001
Posts: 3
date:20/11/2001
from asif ali<prexml@yahoo.com>
subject :uncleared panel topic
sir
please help me undestand awt.
i would like to put panel object in Frame object.
how can i create it in Awt?

import java.awt.*;
class DemoPanel extends Frame{
DemoPanel(){
super("This is second bid");
Panel p = new Panel();// erroe why?
add(p); //error
p.setBounds(100,100,50,50);
p.setVisible(true);
}
public static void main(String arg []){
DemoPanel dd = new DemoPanel();
}
}
asif ali
<prexml@yahoo.com>
Q2. the following statement is hazy .please explain it.
statement1.
"PANEL: Panel is genric container for holding component"
statement2.
"Panel is concrete subclass of container."
thanks for givig time.
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
You need to add:
show();
after the p.setVisible(true); statement.
Also you should add some code to close the window when the user closes it.
This should get you started...
Rowan Brownlee
Ranch Hand

Joined: Aug 07, 2000
Posts: 97
Hi Ali,
I added a setVisible(true) statement to main.
I didn't get any compiler errors at the lines you specify
I don't think that your setBounds statement will work. It will be overridden by the default layout manager for frames (BorderLayout).
Your add statement will by default place the panel in the centre region of the frame, filling all of the available area.
Your questions...
1.) From the API - "Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels. "
2.) From the API for container - "A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT components."
So, a panel is a type of a container. It can hold other components. It's a simple subclass of container.
I hope this is of assistance
(Modified code follows)
cheerio
rowan

import java.awt.*;
class DemoPanel extends Frame{
DemoPanel(){
super("This is second bid");
Panel p = new Panel();// erroe why?
add(p); //error
p.setBounds(100,100,50,50);
//p.setVisible(true);//commented out by rowan


}
public static void main(String arg []){
DemoPanel dd = new DemoPanel();
dd.setVisible(true); //added by rowan
}
}
 
GeeCON Prague 2014
 
subject: uncleared panel topic