Answer the question
In order to leave comments, you need to log in
How to make a button move on click?
Good afternoon!
nButton1.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent ae){
for(int i=0; i<30; i++){
translate.setX(0);
translate.setY(i);
translate.setZ(0);
nButton1.getTransforms().add(translate);
try {
th.sleep(33);
} catch (InterruptedException ex) {
Logger.getLogger(Big_shot.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
});
Answer the question
In order to leave comments, you need to log in
When a window is created , an Event Processing Thread is created , inside which the event loop and event handlers will work. Any events are sent to the event queue, from where they are retrieved and processed at the next iteration of the event loop. Therefore, it is useless to use loops to change the state of GUI elements. Also, you should not try to interact with GUI elements from the main thread or any other thread - this will cause a crash. You should not start threads inside event handlers - this will lead to a crash. And you shouldn't stop the thread - that will crash.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question