简体   繁体   English

在JavaFX中,类Pane的实例是单个节点吗?

[英]In JavaFX, is an instance of class Pane an individual node?

Because typical nodes like Circle or Square are instances of the class Node and Pane is a subclass of Parent which is a subclass of Node, thus, an instance of class Pane used as the root node is technically one individual node. 因为像Circle或Square这样的典型节点是Node类的实例,而Pane是Parent的子类,而Parent是Node的子类,因此从技术上讲,用作根节点的Pane类的实例在技术上是一个单独的节点。 Am I wrong? 我错了吗?

An object of class Pane will always be an instance of Node because Pane is a subclass of Node Pane类的对象将始终是Node的实例,因为Pane是Node的子类

Class Pane :
java.lang.Object
  javafx.scene.Node
    javafx.scene.Parent
      javafx.scene.layout.Region
        javafx.scene.layout.Pane

This means : 这意味着 :

  • p instance of Node will be true, when p is a Pane pPanep instance of Node true
  • Node p = new Pane(); is ok 还可以

I see what you're getting at I think. 我明白你在想什么。 You're asking if the Pane's inheritance hierarchy classes are all floating around along with the Pane. 您要问Pane的继承层次结构类是否都随Pane一起浮动。 The answer is no, they are not and yes, it is a single Node. 答案是否定的,不是,是的,它是单个节点。

When an inheritance hierarchy is instantiated, it is AS IF all the code in each of those parents AND the code from the child, in your case Pane, were all struffed into one class, which you instantiate by calling Pane(). 实例化继承层次结构时,假设每个父级中的所有代码和子级中的所有代码(在您的情况下为Pane)都被拼凑成一个类,则可以通过调用Pane()进行实例化。

It's one big binary blob with all the members and methods of all its parents. 这是一个很大的二进制blob,包含所有父代的所有成员和方法。

The Java language API lets you treat it as if it were three different objects in the sense that you can cast it down the hierarchy and create references to it which are higher up the hierarchy and generally treat it "as if" it was a Node a Container and a Pane at any given time. Java语言API可让您将其视为三个不同的对象,因为您可以将其向下推到层次结构中并创建对它的引用,这些引用位于层次结构中较高的位置,并且通常将其“好像”它是一个Node a。容器和窗格在任何给定时间。

But only one instance of a Java object is created. 但是只创建一个Java对象的实例。 Th exceptino to this is if thre is an inner class. 如果这是一个内部阶级,那么除外。 If there's an inner class then actually, that innner class is created as a separate top-level object- it's its own binary blob. 如果实际上有一个内部类,则该内部类将作为单独的顶级对象创建-它是自己的二进制对象。

HTH 高温超导

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

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