0

我正在构建一个菜单(文件、视图、帮助等)。例如。在文件中你有上传和退出(都工作正常)。在帮助中,我有一些主题:ACF、ARIMA、HoltWinter,这个想法是当您选择其中一个时,将在 GridPane 中显示文本。问题是当你选择一个时,它会显示它的文本,但它也会锁定整个应用程序,除了关闭应用程序之外你什么也做不了。这是一个文件选择器,它工作得很好:

 MenuItem upload = new MenuItem("Upload");
    upload.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Open Resource File");
            fileChooser.showOpenDialog(primaryStage);           
        }
    });

这是一个阻止应用程序的事件:

MenuItem acfH = new MenuItem("ACF");
    acfH.setOnAction(new EventHandler<ActionEvent>(){
        public void handle(ActionEvent event){
            fr.md.pack.TextClass.acfText.setFill(Color.FIREBRICK);
            fr.md.pack.TextClass.acfText.setText(fr.md.pack.StringClass.aboutACF);
            grid.add(fr.md.pack.TextClass.acfText,1,10);
        }
    });

任何建议如何解决这个问题?提前致谢。

这是整个代码:

public class MD extends Application {

@Override
public void start(final Stage primaryStage) throws IOException {

    primaryStage.setTitle("Crude oil price prediction");

    primaryStage.getIcons().add(new Image("file:resources/images/DukeWithHelmet.png"));

    final GridPane grid = new GridPane();   
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Group root = new Group();
    MenuBar menuBar = new MenuBar();
    Scene scene = new Scene(root, 500,500, Color.WHITE);


    scene.getStylesheets().add(this.getClass().getResource("style.css")
               .toExternalForm());

    primaryStage.setTitle("Crude oil price predicition");


    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu file = new Menu("File2");
    MenuItem upload = new MenuItem("Upload");
    upload.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            FileChooser fileChooser = new FileChooser();
            fileChooser.setTitle("Open Resource File");
            fileChooser.showOpenDialog(primaryStage);           
        }
    });

    MenuItem exit = new MenuItem("Exit");
    exit.setMnemonicParsing(true);
    exit.setAccelerator(new KeyCodeCombination(KeyCode.X,KeyCombination.CONTROL_DOWN));
    exit.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
        Platform.exit();
      }
    });

    Menu test = new Menu("Test");

    MenuItem arima = new MenuItem ("ARIMA");
    arima.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {

      }
    });

    MenuItem acf = new MenuItem ("ACF");
    acf.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {

      }
    });

    MenuItem pacf = new MenuItem ("PACF");
    pacf.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {

      }
    });


    MenuItem hw = new MenuItem ("HoltWinters");
    hw.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {

      }
    });

    Menu help = new Menu("Help");

    MenuItem arimaH = new MenuItem ("ARIMA");

    arimaH.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.arimaText.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.arimaText.setText(fr.md.pack.StringClass.aboutArima);
          grid.add(fr.md.pack.TextClass.arimaText, 1, 10);

      }
    });




    MenuItem acfH = new MenuItem("ACF");
    acfH.setOnAction(new EventHandler<ActionEvent>(){
        public void handle(ActionEvent event){
            fr.md.pack.TextClass.acfText.setFill(Color.FIREBRICK);
            fr.md.pack.TextClass.acfText.setText(fr.md.pack.StringClass.aboutACF);
            grid.add(fr.md.pack.TextClass.acfText,1,10);
        }
    });

    MenuItem pacfH = new MenuItem ("PACF");
    pacfH.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.pacfText.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.pacfText.setText(fr.md.pack.StringClass.aboutPACF);
          grid.add(fr.md.pack.TextClass.pacfText, 1, 10);
      }
    });

    MenuItem hwH = new MenuItem ("HoltWinters");
    hwH.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.hwText.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.hwText.setText(fr.md.pack.StringClass.aboutHW);
          grid.add(fr.md.pack.TextClass.hwText, 1, 10);
      }
    });

    Menu about = new Menu("About");

    MenuItem thisS = new MenuItem ("About this software");
    thisS.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.aboutSoft.setText(fr.md.pack.StringClass.aboutSofttext);
          grid.add(fr.md.pack.TextClass.aboutSoft, 1, 40);
      }
    });

    MenuItem R = new MenuItem ("About R");
    R.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.aboutR.setText(fr.md.pack.StringClass.aboutRtext);
          grid.add(fr.md.pack.TextClass.aboutR, 1, 40);
      }
    });

    MenuItem RServe = new MenuItem ("About RServe");
    RServe.setOnAction(new EventHandler<ActionEvent>() {
      public void handle(ActionEvent event) {
          fr.md.pack.TextClass.textRef.setFill(Color.FIREBRICK);
          fr.md.pack.TextClass.textRef.setText(fr.md.pack.StringClass.aboutText);
          grid.add(fr.md.pack.TextClass.textRef, 1, 40);


      }
    });


    file.getItems().addAll(upload,exit);
    test.getItems().addAll(arima,acf,pacf,hw);
    help.getItems().addAll(arimaH,acfH,pacfH,hwH);
    about.getItems().addAll(thisS, R, RServe);


    menuBar.getMenus().addAll(file,test,help,about);


    root.getChildren().addAll(menuBar,grid);

    primaryStage.setScene(scene);
    primaryStage.show();
}

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

}
}

使用的类只包含要显示的字符串:

package fr.md.pack;

public class StringClass {
    final static String aboutText = "Малко информация за RServe.";
    final static String aboutRtext = "Малко инфо за Р";
    final static String aboutSofttext = "Малко инфо за софта";
    final static String aboutArima = "Малко инфо за ARIMA";
    final static String aboutACF = "Малко инфо за ACF";
    final static String aboutPACF = "Малко инфо за PACF";
    final static String aboutHW = "Малко инфо за Holt Winters";

}
4

1 回答 1

0

好吧,我刚刚安装了 Java 8 并感到惊讶....一切正常。到目前为止,我一直使用 Java 1.7 update 45,一旦我尝试使用 Action 事件,它就会锁定我的应用程序。使用 Java 8 它可以工作,但并非没有一些错误......

于 2013-11-19T19:50:35.030 回答