what is the difference between container and panel?

こ雲淡風輕ζ 提交于 2020-01-06 13:43:09

问题


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....


回答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



来源:https://stackoverflow.com/questions/23030636/what-is-the-difference-between-container-and-panel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!