Issue
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);
}
}
Solution
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 By - Uluk Biy
Answer Checked By - Robin (JavaFixing Admin)