Dan
Dan

Reputation: 109

JavaFx multiple click events

I am creating a simple programme in javafx.

private void onClick(final Circle circle) {
    circle.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent mouseEvent) {
            circle.setTranslateX(150.);
        }
    });

}

in the "public void start" i match th created circle with the method "onClick"

onClick(circle1);

this code move a circle to the right. How can I move it multiple times? I tried to create more methods analogically "onClick1" but it always respond just to the first click. I need to move it to the right with each click again.

Thank you for your time.

Upvotes: 1

Views: 232

Answers (1)

mipa
mipa

Reputation: 10640

What about

circle.setTranslateX(circle.getTranslateX() + 150.0);

Upvotes: 1

Related Questions