0

I am really get big confused in container and panel i heard the components which we are adding that will be added to the container object,but also i heard it will added to the panel.... then who display the components on applet... does it display by container or it display by panel?? Also tell me guys the blank white surface are in applet is panel or container??? And What is container???? i also wrote program on container and panel but not understanding the concept of these both..

please clarify my doubts:

  1. if we not create panel object then also the components are visible on applet window...

  2. if we not create container object then also the components are visible on applet window...

generally we use add() to add components on applet but how it get added even we not creating object of panel and container...i try this program by without creating object of panel and container and still it works and it shows the components on applet... how??? please tell me guys i know am asking like a stupidity but please clear my doubts.. because of this confusion i cant forward my study....

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
user3485153
  • 27
  • 2
  • 5
  • 1
    You can look at the [docs](http://docs.oracle.com/javase/7/docs/api/javax/swing/JPanel.html?is-external=true) and class hierarchy. `JPanel` is a sub class of `Container` – Paul Samsotha Apr 12 '14 at 13:25
  • Rather than `Applet`, consider a [hybrid](http://stackoverflow.com/a/12449949/230513). – trashgod Apr 12 '14 at 13:37

1 Answers1

1

Container is a concept and it's implemented by Panel, JFrame or Applet (in your case).

  1. if we not create panel object then also the components are visible on applet window...
    -> yes, because your Jframe, applet is master container, they are able to add component without panel.

  2. if we not create container object then also the components are visible on applet window...
    -> not create container means not create jframe/applet/panel. Of course, nothing to display.

You can see all of them are container in below:
Inheritance tree of JFrame:

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame

Inheritance tree of JApplet:

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet

Inheritance tree of JPanel:

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
rchrd
  • 379
  • 2
  • 6
  • 17
tana
  • 585
  • 1
  • 5
  • 16
  • Dude am talking about APPLET,not a swing... i wanto know if we not creat a object those both panel and container then still the components are visible on applet how????that is my question... is it automatically create a component object for holding components on Applet?? – user3485153 Apr 12 '14 at 13:31
  • 1
    Your applet is a container. The key point is all of them are container. – tana Apr 12 '14 at 13:35
  • see Inheritance tree of JApplet you can see applet is a container – tana Apr 12 '14 at 13:38
  • 1
    @user3485153 The [awt hierarchy](http://docs.oracle.com/javase/8/docs/api/java/awt/Panel.html) is no different, except the components don't extend `JComponent`. Learn to read the docs, if you're confused. – Paul Samsotha Apr 12 '14 at 13:38
  • @user3485153, `Dude am talking about APPLET,not a swing` - then why did you use a Swing tag? By the way you can use a JApplet in Swing. – camickr Apr 12 '14 at 14:45
  • 1) am not using swing 2)read my question carefully...Am talking about only Applet... – user3485153 Apr 14 '14 at 09:16
  • Read my answer carefully! java.applet.Applet, javax.swing.JApplet which your applet app come from? – tana Apr 15 '14 at 09:37
  • I saw your questions on stackoverflow, I see you are beginner in OOP. So, you are hardly to understand my question. Firstly, you need to understand the hierarchy of Applet. – tana Apr 15 '14 at 09:51