import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.layout.VBox; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.paint.Color; import javafx.stage.Stage; public class ChangeColor extends Application { private final Color[] cs = {Color.RED, Color.BLUE, Color.GREEN, Color.ORANGE}; private int i = 0; public void start(Stage stage) { stage.setTitle("Change Color"); Button btn = new Button("Click"); Label label = new Label("HELLO WORLD! Please change my color!"); btn.setOnAction(e -> { i = (i + 1) % cs.length; label.setTextFill(cs[i]); }); VBox root = new VBox(); root.setAlignment(Pos.CENTER); root.getChildren().addAll(btn, label); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); } public static void main(String... args) { launch(args); } }