非常感谢提前!
代码在这里:
package shuffleMyWeb;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class AliceImedemaal extends Application{
@Override
public void start(Stage Beginning) throws Exception {
StackPane stack = new StackPane();
Scene scene = new Scene(stack, 400, 400);
Beginning.setScene(scene);
Beginning.setTitle("Start here");
VBox rows = new VBox();
rows.setAlignment(Pos.CENTER);
rows.setSpacing(50);
stack.getChildren().add(rows);
AnchorPane headerButtons = new AnchorPane();
Button ExitButton = new Button("Exit");
headerButtons.getChildren().add(ExitButton);
headerButtons.setRightAnchor(ExitButton, 10.0);
rows.getChildren().add(headerButtons);
Label reveal = new Label();
reveal.setWrapText(true);
reveal.setText("Generates pages");
rows.getChildren().add(reveal);
Button Go = new Button("Go");
rows.getChildren().add(Go);
AnchorPane footerButtons = new AnchorPane();
Button Seaded = new Button("Settings");
footerButtons.getChildren().add(Seaded);
footerButtons.setLeftAnchor(Seaded, 10.0);
rows.getChildren().add(footerButtons);
Beginning.show();
}
}
答案 0 :(得分:0)
1)只需在下面声明另一个方法,但在类中输入您的整个代码,然后在start()
方法类型methodName();
示例:
@Override
public void start(Stage primaryStage) throws Exception{
method();
}
private void method(){
StackPane stack = new StackPane();
Scene scene = new Scene(stack, 400, 400);
Beginning.setScene(scene);
Beginning.setTitle("Start here");
VBox rows = new VBox();
rows.setAlignment(Pos.CENTER);
rows.setSpacing(50);
stack.getChildren().add(rows);
// and so one
}
2)只需写methodName();
3)创建该类的新对象,然后像这样从他那里调用方法
OtherClass classVariable = new OtherClass();
classVariable.methodName();
注意强>
当方法是静态的时候可能会出现一些问题,所以基本上你需要让两个方法都是静态的,以便同时使用它们。与其他类相同但在这里你不必创建类的对象。如果方法在另一个类中是静态的,那么只需编写OtherClass.methodName();
如果有什么事让你感到困惑,请随时提出其他问题