JavaFX - setOnAction not applicable

后端 未结 2 1227
再見小時候
再見小時候 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");
    });
    

提交回复
热议问题