In: Computer Science
javaFX
is there a way to change the text of a button and then that button repeats to actions of the first button
yes button can we can change text of a button and then that button can repeat action of the first button you can use the bellow code to do that.
import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { Button btn = new Button(); final Label lbl = new Label(); primaryStage.setTitle("Hello World!"); lbl.setLayoutX(70); lbl.setLayoutY(150); btn.setLayoutX(100); btn.setLayoutY(100); btn.setText("Hello, World!"); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { lbl.setText("Hello, World."); } }); Group root = new Group(); root.getChildren().add(btn); root.getChildren().add(lbl); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); } }
/////////////////////////////////////////////////////////////////////////////////////END ////////////////////////////////////////////////////////////////////////////////
# Feel free to like if my answer if it is worth helping to you.
# you can payback and help me with a like.