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

时间:2015-02-16 06:16:26

标签: 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;
    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();
    }
     }

FXml如下。请帮我解决这个问题。如果问题不明确,请帮我解释一下。主要问题是在启动画面后启动应用程序。按钮接受双击,然后移动以加载下一个FXML。这是非常痛苦的,因为我必须每次双击而不是单击。我无法在这里发现问题。是否是从场景构建器持续存在的问题或问题是在主预加载器类中。即使菜单项接受双击。我尝试谷歌解决方案,但找不到任何解决方案。请查看代码并帮助解决此问题。我做了很多R&amp; D但都是徒劳。可能有一点问题,但我无法识别它。请忽略代码和未使用变量的格式。代码还不是最终的。最后我想提醒一下,主要问题是启动后,应用程序只能双击。让我们看一下工作流程,以便更好地理解它。 SPLASH SCREEN-&gt; ACTIVATION WIZARD- 双击按钮 - &gt; TIP SCREEN- 双击按钮 - &gt; PROJECT SCREEN-&gt; DICKBLE CLICK TO OPEN任何东西。真的很令人沮丧。请帮忙。

      <?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>

0 个答案:

没有答案