简体   繁体   English

java awt中的顶级窗口是什么?

[英]What is a top-level window in java awt?

I found this line on the java docs tutorial site- "A Frame is a top-level window with a title and a border". 我在java docs教程网站上找到了这一行 - “一个框架是一个带有标题和边框的顶级窗口”。 Here, what is the meaning of "top-level window"? 这里,“顶级窗口”的含义是什么?

In GUI toolkits such as AWT, a top-level window is a window which is usually known to the OS (heavy-weight components). 在诸如AWT的GUI工具包中,顶级窗口是OS通常已知的窗口(重量级组件)。

Side note: AWT (and even Swing) is a pretty old technology. 旁注:AWT(甚至是Swing)是一项非常古老的技术。 I recommend to use JavaFX where possible. 我建议尽可能使用JavaFX。

A 'top-level window' or 'top level container' is something that can be shown on screen without having to add it to another component. “顶级窗口”或“顶级容器”可以在屏幕上显示,而无需将其添加到另一个组件。 We would start a GUI with a top level container, and then add panels and components to that TLC. 我们将使用顶级容器启动GUI,然后将面板和组件添加到该TLC。 EG of top level containers.. 顶级容器的EG ..

See also this answer for many good reasons to abandon AWT components in favor of Swing. 另请参阅此答案有很多理由放弃AWT组件,转而使用Swing。 As to abandoning Swing for Java-FX, I'll be unwilling to do so until Java-FX is promoted to the Java API's Java docs, and makes it into the official Java Tutorial. 至于放弃Swing for Java-FX,我将不愿意这样做,直到Java-FX被提升为Java API的Java文档,并使其成为官方Java教程。 Sun, then Oracle, has a bad habit of hyping many technologies only to later quietly drop support & development for them. Sun,然后是甲骨文,有一种不好的习惯,即只能在以后悄悄地放弃对它们的支持和开发。

a window without a parent. 没有父母的窗口。

a window can have child windows alright and they have a parent then 一个窗口可以让子窗口正常,然后他们有一个父窗口

Observe difference among these classes. 观察这些类别之间的差异。

Frame is top level window because it has border and title. 框架是顶级窗口,因为它有边框和标题。 An instance of frame can have a menubar. 框架的实例可以具有菜单栏。 Without those it is mere is an instance of java.awt.Window class. 没有它,它只是java.awt.Window类的一个实例。

Window class: It has neither border not title. Window类:它既没有边框也没有标题。 Window class is not attached to nor embedded within another container. Window类未附加到另一个容器中,也未嵌入其中。

Dialog: It has border and title. 对话:它有边框和标题。 An instance of the Dialog class cannot exist without an associated instance of the Frame class. 没有Frame类的关联实例,Dialog类的实例不能存在。

Panel: just a generic container to hold components. Panel:只是一个容纳组件的通用容器。 Its instance provides a container to which to add components. 它的实例提供了一个可以添加组件的容器。

Note: Revert me back if further clarification is required. 注意:如果需要进一步说明,请将其还原。

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

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