我试图运行这个简单的Javafx代码:
public class Javafx extends Application
{
Stage window;
Scene scene1,scene2;
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) throws Exception{
window = primaryStage;
Label label1 = new Label("click here to go to scene 2");
Button button1 = new Button("click here");
button1.setOnAction(e-> window.setScene(scene2));
VBox layout1 = new VBox(15);
layout1.getChildren().addAll(label1,button1);
scene1 = new Scene(layout1,700,900);
Label label2 = new Label("get back to scene1");
Button button2 = new Button("press");
button2.setOnAction(e-> window.setScene(scene1));
StackPane layout2 = new StackPane();
label2.setRotate(70);
layout2.getChildren().addAll(label2,button2);
scene2 = new Scene(layout2,500,500);
window.setScene(scene1);
window.setTitle("Java FX");
window.show();
}
}
但由于某些原因我关闭应用并重新运行后,我发现了一个错误: 应用luanch不能多次调用。 据我所知,启动应用程序只调用一次,但我再次重新运行它的唯一方法是首先重置JVM。
谁能告诉我怎么能克服这个? 如果这很重要,我会使用Bluej