合理的布局设计,不仅使图形界面更美观,也让逻辑更清晰,布局和合理的JavaFX结构更有利于维护——在JavaFX中看到布局二字条件反射的要想到layout包,这是一个专门用来做布局的JavaFX包——本文的行文顺序是按照JavaFX布局从底层往外层进行的
java.lang.Object
javafx.stage.Window
javafx.stage.Stage
public class Stage extends Window
/** Create a new instance of decorated Stage. */
Stage()
/** Create a new instance of Stage. */
Stage(StageStyle style)
/** Defines whether this Stage is kept on top of other windows. */
ReadOnlyBooleanProperty alwaysOnTopProperty()
/** Close this stage. */
void close()
/** Sets the value of property alwaysOnTop. */
void setAlwaysOnTop(boolean value)
/** Sets the value of property fulScreen. */
void setFullScreen(boolean value)
/** Sets the value of the property maxHeight. */
void setMaxHeight(boolean value)
/** Sets the vlaue of the property maxminized. */
void setMaximized(boolean value)
/** Sets the vlaue of the property maxWidth. */
void setMaxWidth(boolean value)
/** Sets the value of the property resizable. */
void setResizable(boolean value)
/** Specify the scene to be used on this stage. */
void setScene(Scene value)
/** Sets th value of the property title. */
void setTitle(String value)
/** Send the Window to the background. */
void toBack()
/** Send the Window to the foreground. */
void toFront()
java.lang.Object
javafx.scene.Scene
@DefaultProperty(value="root")
public class Scene extends Object implements EventTarget
/** Creates a Scene for a specific root Node. */
Scene(Parent root)
/** Creates a Scene for a specific root Node with a specific size. */
Scene(Parent root, double width, double height)
这里之所以报错,是因为构造Scene对象必须同时指定其顶层结点
顶层结点,既是Node,也是Parent
Parent
包括Pane
、Group
、Control
Pane
包括FlowPane
、GridPane
、BorderPane
、HBox
、VBox
、StackBox
注意到setCenter(Node node)
方法传入了一个Button
对象,它既是一个Parent,而根据继承的is-a
关系也是一个Node
暂时用不到,占坑
Control
其实是UI Control
的简写(不过当然没有这个类 :-)
意思是:用户控制接口,就是提供相应的组件用来相应用户做出的动作
Control
是一个抽象类
Control
包括TextField
、Button
、CheckBox
、RadioButton
、TextArea
,它们都是Control
的子类
如果考虑is-a
关系,所有的Parent
都是Node
但这里仅考虑作为叶子结点的Node对象
它们是Shape
、ImageView
Shape
全称javafx.scene.shape.Shape
Shape
是一个抽象类
Shape
包括Line
、Circle
、Ellipse
、Rectangle
、Arc
、Polygon
、Polyline
、Text
,它们都是Shape
的子类
ImageView
类用来演示/绘制一个具体的图像
可以通过以下构造方法创建一个Imageview
对象
/** Allocates a new ImageView object. */
ImageView()
/** Allocates a new ImageView object using the given image. */
ImageView(Image image)
/** Allocates a new ImageView object with image loaded from the specified URL. */
ImageView(String url)
Node
对象作为JavaFX程序的最外层,距离用户最近,也最容易实现交互