简体   繁体   中英

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. Am I wrong?

An object of class Pane will always be an instance of Node because Pane is a subclass of 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
  • 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. 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().

It's one big binary blob with all the members and methods of all its parents.

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.

But only one instance of a Java object is created. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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