import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.GridPane; import javafx.scene.layout.StackPane; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.control.Button; import javafx.event.*; public class Rutenett extends Application { private class Ruteknapp extends Button { private Ruteknapp(String s) { super(s); setMaxWidth(50); setMaxHeight(50); setMinWidth(50); setMinHeight(50); setStyle("-fx-background-color: white; "); setOnMouseEntered((m) -> setStyle("-fx-cursor: hand;")); setOnMouseExited((m) -> setStyle("-fx-cursor: pointer; ")); Knappebehandler behandler = new Knappebehandler(); setOnAction(behandler); } } class Knappebehandler implements EventHandler { @Override public void handle(ActionEvent e) { Ruteknapp ruteknapp = (Ruteknapp) e.getSource(); ruteknapp.setStyle("-fx-background-color: black;"); } } @Override public void start(Stage stage) { GridPane pane = new GridPane(); int teller = 1; for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { Ruteknapp r = new Ruteknapp("" + teller); StackPane cell = new StackPane(); cell.getChildren().add(r); pane.add(cell, j, i); teller++; } } Scene scene = new Scene(pane); stage.setScene(scene); stage.setTitle("Rutenett"); stage.show(); } public static void main(String[] args) { Application.launch(args); } }