import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.text.TextAlignment; import javafx.scene.text.Font; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.layout.Border; import javafx.scene.layout.BorderStroke; import javafx.scene.layout.BorderStrokeStyle; import javafx.scene.layout.BorderWidths; import javafx.scene.paint.Color; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.event.Event; public class UIBspAction7 extends Application implements EventHandler{ private final String BN1="Bn1"; private final String BN2="Bn2"; private Label label = null; @Override public void start(Stage stage) { VBox root = new VBox(22); root.setAlignment(Pos.CENTER); root.setFillWidth(true); Button bn1 = new Button("1. Klick") ; bn1.setWrapText(true); bn1.setTextAlignment(TextAlignment.CENTER); bn1.setFont(new Font(22)); bn1.setMaxWidth(Double.POSITIVE_INFINITY); bn1.setPadding( new Insets(10) ); bn1.setOnAction(this); bn1.setId(BN1); Button bn2 = new Button("2. Klick") ; bn2.setWrapText(true); bn2.setTextAlignment(TextAlignment.CENTER); bn2.setFont(new Font(22)); bn2.setMaxWidth(Double.POSITIVE_INFINITY); bn2.setPadding( new Insets(10) ); bn2.setOnAction(this); bn2.setId(BN2); root.getChildren().addAll(bn1, bn2); label = new Label("Hier ist Text") ; label.setWrapText(true); label.setTextAlignment(TextAlignment.CENTER); label.setFont(new Font("Courier New",22)); root.getChildren().add(label); Scene scene= new Scene(root, 250, 250); stage.setTitle("UIBspAction6"); stage.setScene(scene); stage.show(); } @Override public void handle(Event e) { Control control = (Control) e.getSource(); String id = control.getId(); if(id.equals(BN1)){ label.setText("Der 1. Schalter wurde angeklickt"); } if(id.equals(BN2)){ label.setText("Der 2. Schalter wurde angeklickt"); } } public static void main(String[] argv) { launch(argv); } }