0

i have a fxml file and in my fxmlcontroller class i implement Initializable and i have a stackpane and a button in my fxml file i want to add a Mouse pressed event to my btn but it not has any setOnAction method (i think because i didn't extends application in my class) now i want to add mouse event handler but i can't . any ideas? thanks in advance.

 public class menuController implements Initializable{
 static int seconds=0;
 @FXML StackPane stackPane;
 @FXML Button btn;
 @Override
 public void initialize(URL location, ResourceBundle resources) {
 btn.setOnAction(nothing found); 
}
}
asked May 7, 2014 at 15:25

1 Answer 1

2

You may be importing wrong Button. Import JavaFX's button as

import javafx.scene.control.Button;

then add event handler like

btn.setOnAction(new EventHandler<ActionEvent>() {
 @Override
 public void handle(ActionEvent event) {
 System.out.println("Button clicked");
 }
 });
answered May 7, 2014 at 15:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.