简体   繁体   English

我的按钮无法打开我的课程

[英]My button can't open my class

Basically, the problem is I created an interface with Java Scene Builder. 基本上,问题是我使用Java Scene Builder创建了一个接口。 And from FXML button I wanted to open my class. 从FXML按钮,我想打开我的课程。

    @FXML
    public void pressButton(ActionEvent event) throws Exception {
    Platform.runLater(() -> {
        try{
            new SerialChart().start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    }

    @FXML
    public void pressButton2(ActionEvent event) throws Exception {                      
    Platform.runLater(() -> {
         try {
            new Main().start(new Stage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
    }

And my Main can be open, but my SerialChart can't be opened. 我的Main可以打开,但是我的SerialChart无法打开。 It says "The constructor SerialChart() is undefined". 它说“构造函数SerialChart()未定义”。 So here is the problem I think 所以这是我认为的问题

    public SerialChart(String title) {  
    super(title);

I think this is the problem why I can't open. 我认为这就是为什么我无法打开的问题。 Please help me... I can show you the whole code if you need. 请帮助我...如果您需要,我可以向您显示整个代码。

Like Jim Garrisson said, your constructor that you call takes no arguments, but your defined one does (String title). 就像吉姆·加里森(Jim Garrisson)所说的那样,您调用的构造函数不带参数,但定义的参数带参数(字符串标题)。 This means you need to pass in a String argument (Even a blank one like "" will work) when you call it in the Button function. 这意味着在Button函数中调用它时,您需要传递一个String参数(即使像“”这样的空白参数也可以使用)。

new SerialChart("Some Title").start(new Stage()); //should be your call in the Button function.

so this is the answer I figured out SO HAPPY 所以这就是我想出来的答案

    public void pressButton(ActionEvent event) throws Exception {
    Platform.runLater(() -> {
        try{
            SerialChart serialChartDemo = new SerialChart("Clean Energy Data Real time graph");
            serialChartDemo.pack();  
            RefineryUtilities.centerFrameOnScreen(serialChartDemo);  
            serialChartDemo.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM