Benyamin Noori
Benyamin Noori

Reputation: 880

Handling mouse event in javafx: how to add listener?

I have a problem with the event handler, this is the code. There is a compile error. NetBeans says: cannot find symbol, method setOnAction. This is exactly like the example I found at Oracle Doxs.

And then I have another question: how should i use this listener? by creating an object in main?

public class StartButtonController implements Initializable {

    @FXML private Button startButton;
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
        } catch (IOException ex) {
            Logger.getLogger(StartButtonController.class.getName()).log(Level.SEVERE, null, ex);
        }

        startButton.setOnAction(new EventHandler<ActionEvent>(){

            @Override
            public void handle(ActionEvent event) {
                startButton.setForeground(Color.BLACK);
                startButton.setEnabled(false);
            }
        });
    }

Thanks for your help.

Upvotes: 0

Views: 1173

Answers (1)

Uluk Biy
Uluk Biy

Reputation: 49185

import javafx.scene.control.Button.
and
remove the line import java.awt.Button;

Upvotes: 1

Related Questions