我只是 javafx 的初学者。我只是在 ensemble.jar 中看到了一些示例,并且对以下程序有疑问。这里有 2 种方法start
,init
它们都接受 type 的参数Stage
。init()
是从调用的。start()
我怀疑舞台装饰(添加组,进度指示器,网格窗格)是在启动方法中完成的。primaryStage.show()
所以会显示装饰的舞台,但在这里如果我写primaryStage1.show()
在start()
然后装饰的舞台也正在显示。我想知道如何
包外汇;
/**
* Copyright (c) 2008, 2012 Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*/
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.GridPane;
/**
* A sample that demonstrates the Progress Indicator control in various modes.
*
* @see javafx.scene.control.ProgressIndicator
* @related controls/ProgressBar
*/
public class ProgressIndicatorSample extends Application {
private void init(Stage primaryStage) {
Group root = new Group();
primaryStage.setResizable(false);
primaryStage.setScene(new Scene(root, 400,400));
GridPane g = new GridPane();
ProgressIndicator p1 = new ProgressIndicator();
p1.setPrefSize(50, 50);
ProgressIndicator p2 = new ProgressIndicator();
p2.setPrefSize(50, 50);
p2.setProgress(0.25F);
ProgressIndicator p3 = new ProgressIndicator();
p3.setPrefSize(50, 50);
p3.setProgress(0.5F);
ProgressIndicator p4 = new ProgressIndicator();
p4.setPrefSize(50, 50);
p4.setProgress(1.0F);
g.add(p1, 1, 0);
g.add(p2, 0, 1);
g.add(p3, 1, 1);
g.add(p4, 2, 1);
char x[]={'a','m'};
x.toString();
System.out.println(x);
g.setHgap(40);
g.setVgap(40);
root.getChildren().add(g);
}
public double getSampleWidth() { return 400; }
public double getSampleHeight() { return 400; }
@Override public void start(Stage primaryStage1) throws Exception {
init(primaryStage1);
primaryStage1.show();
}
public static void main(String[] args) { launch(args); }
}