当前位置: 技术问答>java相关
请问创建一个JFrame与JPanel有什么不同?
来源: 互联网 发布时间:2015-10-08
本文导语: 请问创建一个JFrame与JPanel有什么不同? | JFrame是个窗体,JPanel是放其他控键的容器! | JFrame可作为应用程序的载体,而JPanel却不行! | JFrame是顶级容器,而JPanel...
请问创建一个JFrame与JPanel有什么不同?
|
JFrame是个窗体,JPanel是放其他控键的容器!
|
JFrame可作为应用程序的载体,而JPanel却不行!
|
JFrame是顶级容器,而JPanel是普通容器。包含Swing组件的程序必须包含一个顶级容器,而Swing组件不可以直接加入到顶级容器中。Sun文档有下列相关的解释:
1、The containment hierarchy for any window or applet that contains Swing components must have a Swing top-level container at the root of the hierarchy.
2、You don't add components directly to a top-level container such as a Jframe, and you should add components to a container (called the content pane) that is itself contained by the JFrame.
3、Swing provides three generally useful top-level container classes: JFrame, JDialog, and JApplet
至于其他的不同,它们既然是不同的类,自然不同了,可以看看API文档。
1、The containment hierarchy for any window or applet that contains Swing components must have a Swing top-level container at the root of the hierarchy.
2、You don't add components directly to a top-level container such as a Jframe, and you should add components to a container (called the content pane) that is itself contained by the JFrame.
3、Swing provides three generally useful top-level container classes: JFrame, JDialog, and JApplet
至于其他的不同,它们既然是不同的类,自然不同了,可以看看API文档。
|
JFrame就象是房间,JPane相当于箱子
明白了?
明白了?
|
JFrame是一個框架,而JPanel是一個容器