简体   繁体   English

与JFrame和JPanel对象int Java Swing有区别吗?

[英]Difference from JFrame and JPanel object int Java Swing?

I know that JFrame is a top level container fro Swing GUI and that I can put a JPanel object inside a JFrame object. 我知道JFrame是Swing GUI的顶级容器,并且我可以将JPanel对象放在JFrame对象中。

But also JPanel is a container...so what is the difference from JFrame and JPanel. 而且JPanel是一个容器...因此,与JFrame和JPanel有什么区别。

I see that, in the GUI implementation, is implement directly a JPanel object, other times I see that is implemented a JFrame in which I put a JPanel. 我看到在GUI实现中,是直接实现JPanel对象,而其他时候,我看到是实现了放置JPanel的JFrame。

What is the difference? 有什么区别?

Tnx 特纳克斯

Andrea 安德里亚

JFrame - Used to represent the features a like a window. JFrame-用于表示功能,例如窗口。 This includes border,titlebar, different controls, and different event handlers. 这包括边框,标题栏,不同的控件和不同的事件处理程序。 refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html 参考: http : //docs.oracle.com/javase/6/docs/api/javax/swing/JFrame.html

JPanel - Most Generic class used as a container to gather other elements together. JPanel-最通用的类​​,用作将其他元素收集在一起的容器。 This is more important with working with the visual layout or one of the provided layout managers. 这对于使用视觉布局或提供的布局管理器之一更为重要。 refer : http://docs.oracle.com/javase/6/docs/api/javax/swing/JPanel.html 请参阅: http : //docs.oracle.com/javase/6/docs/api/javax/swing/JPanel.html

EDIT: Some more 编辑:更多

  1. JPanel serves as a general purpose container, while JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window. JPanel用作通用容器,而JFrame是通常用于独立应用程序的窗口,例如警告窗口或通知窗口。
  2. JPanel represents an area used for more complex operations or applications. JPanel表示用于更复杂的操作或应用程序的区域。
  3. In JPanel, one panel can hold many operations, while in JFrame, it can have inner frames for a different purpose. 在JPanel中,一个面板可以容纳许多操作,而在JFrame中,它可以具有用于不同用途的内部框架。 Read more: Difference Between JPanel and JFrame | 阅读更多:JPanel和JFrame之间的区别 Difference Between | 之间的区别 JPanel vs JFrame http://www.differencebetween.net/technology/difference-between-jpanel-and-jframe/#ixzz2g0DDAgAq JPanel与JFrame http://www.differencebetween.net/technology/difference-between-jpanel-and-jframe/#ixzz2g0DDAgAq
  1. The similarity is both are containers. 两者都是容器。
  2. JFrame is a contrainer which can hold JPanel. JFrame是可以容纳JPanel的约束器。
  3. The best use when I had used long days back, when I inherit JPanel instead JFrame, so latter on, the component can be used in both JFrame and JApplet. 当我使用了很长一段时间后,当我继承了JPanel而不是JFrame时,是最好的用法,因此以后,该组件可以在JFrame和JApplet中使用。
  4. You can add multiple JPanels inside a JFrame. 您可以在一个JFrame中添加多个JPanel。 You can set the different layouts. 您可以设置不同的布局。
  • Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (eg, buttons, checkboxes, and textfields) and visuals (eg, figures, pictures, and even text) can appear. 基本上,JFrame表示框架的窗口,而JPanel表示可以在其中显示控件(例如按钮,复选框和文本字段)和视觉效果(例如图形,图片甚至文本)的某个区域。

  • JPanel serves as a general purpose container, while JFrame is a window commonly used for stand-alone applications, like a warning window, or a notification window. JPanel用作通用容器,而JFrame是通常用于独立应用程序的窗口,例如警告窗口或通知窗口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM