Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.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独立应用程序接受双击?_Java_Javafx 8_Fxml_Double Click - Fatal编程技术网

为什么Javafx独立应用程序接受双击?

为什么Javafx独立应用程序接受双击?,java,javafx-8,fxml,double-click,Java,Javafx 8,Fxml,Double Click,这是我的主要java文件。问题是当我启动它时,整个项目都在双击 public Stage primaryStage; public BorderPane rootLayout; private Pane splashLayout; private ProgressBar loadProgress; private Label progressText; private static final int SPLASH_WIDTH = 600;

这是我的主要java文件。问题是当我启动它时,整个项目都在双击

    public Stage primaryStage;
    public BorderPane rootLayout;
    private Pane splashLayout;
    private ProgressBar loadProgress;
    private Label progressText;
    private static final int SPLASH_WIDTH = 600;
    private static final int SPLASH_HEIGHT = 400;

    public static void main(String[] args) throws Exception {
        launch(args);
    }


    @Override
    public void start(final Stage initStage) throws Exception {
          //this.primaryStage = primaryStage;

        FXMLLoader fxmlLoader1 = new FXMLLoader(getClass().getResource(
                "KDAF_Splash.fxml"));
                try {
                   // flag = false;
                    Parent root2 = fxmlLoader1.load();

                     Stage stage2 = new Stage();
                    stage2.initStyle(StageStyle.TRANSPARENT);
                 //   masterpane = new Pane();
                   // masterpane.setOpacity(1);
                   // stage2.setTitle("Create New Project");
                    stage2.setScene(new Scene(root2, 600, 400));
                    stage2.show();
                    PauseTransition delay = new PauseTransition(Duration.seconds(5));
                    delay.setOnFinished( event ->{ stage2.close();showMainStage();} );

                    delay.play();

                    } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }

        };




    private void showMainStage(
    ) {
          try {
              // Load root layout from fxml file.
              FXMLLoader loader = new FXMLLoader();
              loader.setLocation(Preloader.class.getResource("RootLayout.fxml"));
              rootLayout = (BorderPane) loader.load();
              Stage stage=new Stage();
              stage.setTitle("Activation");
              Scene scene = new Scene(rootLayout);
              //stage.initStyle(StageStyle.DECORATED);
              stage.setScene(scene);
              stage.initStyle(StageStyle.UNDECORATED);

              stage.show();
              showPersonOverview();
              //mainStage.show();
          /*    mainStage.setTitle("Activation Wizard");
              // Show the scene containing the root layout.
              Scene scene = new Scene(rootLayout);
             // primaryStage.initStyle(StageStyle.UTILITY);
              mainStage.setResizable(false);

              mainStage.initStyle(StageStyle.UNDECORATED);
              mainStage.setScene(scene);
              mainStage.show();
            showPersonOverview();*/

          } catch (IOException e) {
              e.printStackTrace();
          }
    }
    public void showPersonOverview() {
        try {
            // Load person overview.
            FXMLLoader loader = new FXMLLoader();
            loader.setLocation(MainApp.class.getResource("activation wizard.fxml"));
            AnchorPane personOverview = (AnchorPane) loader.load();
            personOverview.setPrefHeight(400);           
            // Set person overview into the center of root layout.



            rootLayout.setCenter(personOverview);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void showSplash(
            final Stage initStage,
            Task<?> task,
            InitCompletionHandler initCompletionHandler
    ) {
        progressText.textProperty().bind(task.messageProperty());
        loadProgress.progressProperty().bind(task.progressProperty());
        task.stateProperty().addListener((observableValue, oldState, newState) -> {
            if (newState == Worker.State.SUCCEEDED) {
                loadProgress.progressProperty().unbind();
                loadProgress.setProgress(1);
                initStage.toFront();
                FadeTransition fadeSplash = new FadeTransition(Duration.seconds(1.2), splashLayout);
                fadeSplash.setFromValue(1.0);
                fadeSplash.setToValue(0.0);
                fadeSplash.setOnFinished(actionEvent -> initStage.hide());
                fadeSplash.play();

                initCompletionHandler.complete();
            } // todo add code to gracefully handle other task states.
        });

        Scene splashScene = new Scene(splashLayout);
        initStage.initStyle(StageStyle.UNDECORATED);
        final Rectangle2D bounds = Screen.getPrimary().getBounds();
        initStage.setScene(splashScene);
        initStage.setX(bounds.getMinX() + bounds.getWidth() / 2 - SPLASH_WIDTH / 2);
        initStage.setY(bounds.getMinY() + bounds.getHeight() / 2 - SPLASH_HEIGHT / 2);
        initStage.show();
    }

    public interface InitCompletionHandler {
        public void complete();
    }
     }
公共舞台初级舞台;
公共边界布局;
专用窗格布局;
私人进度条加载进度;
私有标签文本;
专用静态最终int飞溅_宽度=600;
专用静态最终内部飞溅高度=400;
公共静态void main(字符串[]args)引发异常{
发射(args);
}
@凌驾
public void start(final Stage initStage)引发异常{
//this.primaryStage=primaryStage;
FXMLLoader fxmlLoader1=新的FXMLLoader(getClass().getResource(
“KDAF_Splash.fxml”);
试一试{
//flag=false;
父root2=fxmloader1.load();
阶段2=新阶段();
stage2.initStyle(StageStyle.TRANSPARENT);
//主窗格=新窗格();
//主窗格。设置不透明度(1);
//阶段2.设置标题(“创建新项目”);
第二阶段:设置场景(新场景(root2600400));
stage2.show();
暂停转换延迟=新的暂停转换(持续时间。秒(5));
delay.setOnFinished(事件->{stage2.close();showmostrage();});
延迟。播放();
}捕获(IOException异常){
抛出新的RuntimeException(异常);
}
};
私人虚空展示(
) {
试一试{
//从fxml文件加载根布局。
FXMLLoader=新的FXMLLoader();
setLocation(preload.class.getResource(“RootLayout.fxml”);
rootLayout=(BorderPane)loader.load();
阶段=新阶段();
阶段。片名(“激活”);
场景=新场景(根布局);
//舞台风格(舞台风格装饰);
舞台场景;
舞台风格(舞台风格。未装饰);
stage.show();
showPersonOverview();
//show();
/*mainStage.setTitle(“激活向导”);
//显示包含根布局的场景。
场景=新场景(根布局);
//initStyle(StageStyle.UTILITY);
mainStage.setresizeable(false);
主干。初始样式(舞台样式。未装饰);
主干。场景(场景);
show();
showPersonOverview()*/
}捕获(IOE异常){
e、 printStackTrace();
}
}
public void showPersonOverview(){
试一试{
//装载人员概述。
FXMLLoader=新的FXMLLoader();
setLocation(MainApp.class.getResource(“activation wizard.fxml”);
AnchorPane personOverview=(AnchorPane)loader.load();
个人俯视高度(400);
//将人员概览设置到根布局的中心。
rootLayout.setCenter(personOverview);
}捕获(IOE异常){
e、 printStackTrace();
}
}
私人空间展示(
最后阶段,,
任务任务,
InitCompletionHandler InitCompletionHandler
) {
progressText.textProperty().bind(task.messageProperty());
loadProgress.progressProperty().bind(task.progressProperty());
task.stateProperty().addListener((ObservalEvalue、oldState、newState)->{
if(newState==Worker.State.successed){
loadProgress.progressProperty().unbind();
loadProgress.setProgress(1);
initStage.toFront();
FadeTransition fadeSplash=新的FadeTransition(持续时间。秒(1.2),飞溅布局);
FadesFlash.setFromValue(1.0);
fadeSplash.setToValue(0.0);
setOnFinished(actionEvent->initStage.hide());
flash.play();
initCompletionHandler.complete();
}//todo添加代码以优雅地处理其他任务状态。
});
场景splashScene=新场景(splashLayout);
initStage.initStyle(StageStyle.UNDECORATED);
最终矩形2D边界=Screen.getPrimary().getBounds();
初始阶段。设置场景(splashScene);
setX(bounds.getMinX()+bounds.getWidth()/2-SPLASH_WIDTH/2);
initStage.setY(bounds.getMinY()+bounds.getHeight()/2-SPLASH_HEIGHT/2);
initStage.show();
}
公共接口InitCompletionHandler{
公共无效完成();
}
}
下面给出了FXml。请帮我解决这个问题。如果问题不清楚,请帮助我更好地解释。主要问题是启动屏幕后启动应用程序的时间。该按钮接受双击,然后移动到加载下一个FXML。这是非常痛苦的,因为我每次都要双击而不是单击。我无法确定这里的问题。无论是场景生成器中持续存在的问题还是主预加载程序类中的问题。甚至菜单项也接受双击。我试图用谷歌搜索解决方案,但找不到任何解决方案。请查看代码并帮助解决此问题。我做了很多研发工作,但都失败了。这里面可能有点小问题,但我无法确定。请忽略代码和未使用变量的格式设置。代码还不是最终版本。最后,我想提醒一下,主要问题是,启动后,应用程序只需双击即可工作。让我们看看工作流程,以便更好地理解它。启动屏幕->激活向导-双击按钮-
      <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" style="-fx-border-color: black;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="EventHandlingController">
   <children>
      <Button layoutX="301.0" layoutY="333.0" mnemonicParsing="false" text="Buy Full Version" />
      <Button fx:id="myButton7" layoutX="420.0" layoutY="333.0" mnemonicParsing="false" onAction="#Showtip" prefHeight="25.0" prefWidth="114.0" text="Continue Trial " />
      <TextField editable="false" layoutX="85.0" layoutY="108.0" prefHeight="151.0" prefWidth="449.0" style="-fx-background-color: silver;" text="You have &lt;xx&gt; days left on your trial.">
         <font>
            <Font size="21.0" />
         </font>
      </TextField>
      <Label layoutX="85.0" layoutY="23.0" prefHeight="37.0" prefWidth="135.0" text="Activation Wizard">
         <font>
            <Font name="System Bold" size="15.0" />
         </font>
      </Label>
      <Button fx:id="closebutt" layoutX="573.0" layoutY="2.0" mnemonicParsing="false" onAction="#closebuttonD" prefHeight="15.0" prefWidth="20.0" text="X" />
   </children>
</AnchorPane>