JavaFX - setOnAction not applicable

后端 未结 2 1225
再見小時候
再見小時候 2020-12-04 00:44

I am trying to learn JavaFX, and I\'ve written the code shown down below, however I seem to be having trouble with this line of code:

btn.setOnAction(new Eve         


        
相关标签:
2条回答
  • 2020-12-04 01:07

    You have imported awt event listener just change this line of code

    import java.awt.event.ActionEvent;
    

    with this

    import javafx.event.ActionEvent;
    

    and you can also use lambda expression like this

    btn.setOnAction((event) -> {
      System.out.println("Button clicked");
    });
    
    0 讨论(0)
  • 2020-12-04 01:12

    You're mixing up Javafx with Swing. Replace

    import java.awt.event.ActionEvent;
    

    with

    import javafx.event.ActionEvent;
    
    0 讨论(0)
提交回复
热议问题