Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javaFx应用程序&x27;s启动方法_Java_Javafx - Fatal编程技术网

javaFx应用程序&x27;s启动方法

javaFx应用程序&x27;s启动方法,java,javafx,Java,Javafx,伙计们,我有一个问题,这是我的代码,这是一个游戏的15个样本,当我显示洗牌场景,如图所示 现在我想让用户移动,改变场景并再次显示,直到游戏结束,但当我在PrimaryStage.show()之后放置时,它崩溃了,所以我的问题是如何改变场景并再次显示 public class Q3 extends Application { static Label lab[] ; static Rectangle rec[] ; static int X = 3,Y = 3; static int[] ar

伙计们,我有一个问题,这是我的代码,这是一个游戏的15个样本,当我显示洗牌场景,如图所示

现在我想让用户移动,改变场景并再次显示,直到游戏结束,但当我在PrimaryStage.show()之后放置时,它崩溃了,所以我的问题是如何改变场景并再次显示

public class Q3 extends Application {
static Label lab[] ;
static Rectangle rec[] ;
static int X = 3,Y = 3;
static  int[] arr = new int[16];
public static void main(String[] args) {launch(args);
}

@Override
public void start(Stage primaryStage) throws IOException,terruptedException {
    Scanner in = new Scanner(System.in);
    AnchorPane root = new AnchorPane();
    Scene myScene = new Scene(root,301,301);
    rec = new Rectangle[15];
    lab = new Label[15];
    int x = 0,y = 0,Fit = 0;
    arr[15] = 0;
    for(int i = 0;i < 15; i++){
        rec[i] = new Rectangle(20,20,75,75);
        lab[i] = new Label(Integer.toString(i+1));
        rec[i].setEffect(new InnerShadow());
        if(x > 3) {
            x = 0;
            y++;
        }
        Fit = (i < 9) ? 2 : 0;
        lab[i].setTextFill(Color.PERU);
        lab[i].setLayoutX(35 + x * 75 + Fit );
        lab[i].setLayoutY(31 + y * 75 + Fit );
        arr[i] = i;
        rec[i].setX( 1 + x++ * 75);
        rec[i].setY( 1 + y * 75);
        rec[i].setAccessibleText(Integer.toString(i));
        rec[i].setStroke(Color.OLIVE);
        rec[i].setFill(Color.LIGHTBLUE);
        root.getChildren().addAll(rec[i],lab[i]);
    }
    primaryStage.setTitle("The Game Of 15");
    primaryStage.setResizable(true);
    primaryStage.setScene(myScene);
    for(int i = 0;i < 1000;i++){
        shuffle();
    }
    primaryStage.show();
    while(!isfinished()){
       char c = in.next().trim().charAt(0);
       if(c == 'w'){
           do something
       }
       else if ...
    }
}
public类Q3扩展应用程序{
静态标签实验室[];
静态矩形rec[];
静态整数X=3,Y=3;
静态int[]arr=新int[16];
公共静态void main(字符串[]args){launch(args);
}
@凌驾
public void start(Stage primaryStage)抛出IOException、terruptedException{
扫描仪输入=新扫描仪(系统输入);
锚烷根=新锚烷();
场景myScene=新场景(root,301301);
rec=新矩形[15];
实验室=新标签[15];
int x=0,y=0,Fit=0;
arr[15]=0;
对于(int i=0;i<15;i++){
rec[i]=新矩形(20,20,75,75);
lab[i]=新标签(Integer.toString(i+1));
rec[i].setEffect(新的InnerShadow());
如果(x>3){
x=0;
y++;
}
拟合=(i<9)?2:0;
实验室[i].SettexFill(Color.PERU);
实验室[i].设置布局x(35+x*75+Fit);
实验室[i].设置布局(31+y*75+Fit);
arr[i]=i;
rec[i].setX(1+x++*75);
rec[i].setY(1+y*75);
rec[i].setAccessibleText(Integer.toString(i));
rec[i].setStroke(Color.OLIVE);
rec[i].setFill(Color.LIGHTBLUE);
root.getChildren().addAll(rec[i],lab[i]);
}
初级阶段。片名(“15人游戏”);
primaryStage.SetResizeable(真);
初生阶段:集新世(myScene);
对于(int i=0;i<1000;i++){
洗牌();
}
primaryStage.show();
而(!isfinished()){
char c=in.next().trim().charAt(0);
如果(c=='w'){
做点什么
}
否则如果。。。
}
}

以下是javafx中切换工作原理的示例代码:

public class SwitchingScene extends Application {

    public static void main(String[] args) {
        launch(args);
    }
Stage stage;
    @Override
    public void start(Stage window) throws Exception {
        VBox layout1= new VBox(20);
        Button b1=  new Button("Goto Scene2");
        Button b2=  new Button("Goto Scene1");
        StackPane layout2= new StackPane();
        layout2.getChildren().add(b2);
        Scene scene2= new Scene(layout2,200,200);
        Scene scene1= new Scene(layout1,300,400);
        b1.setOnAction(e-> window.setScene(scene2));
        b2.setOnAction(e-> window.setScene(scene1));
        layout1.getChildren().addAll(new Label("Scene1"),b1);
        window.setScene(scene1);
        window.setTitle("My Window");
        window.show();

    }

}

我现在无法浏览您的代码以了解您所做的工作,但您可以参考此代码以了解切换是如何工作的。在按钮操作侦听器上,我已经完成了切换。

这根本不是JavaFX的工作方式:它是事件驱动的。如果您阻止FX应用程序线程,它将无法更新UI。在GUI应用程序中,它将无论如何,从标准输入中读取数据并没有任何意义;GUI应用程序的关键在于用户与UI中的控件进行交互。您应该编写处理用户事件的事件处理程序(例如,您创建的分幅上可能有鼠标侦听器等)。