Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package klausur;
- import java.util.Random;
- import javafx.application.Application;
- import javafx.geometry.Insets;
- import javafx.geometry.Pos;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.Background;
- import javafx.scene.layout.BackgroundFill;
- import javafx.scene.layout.BorderPane;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.StackPane;
- import javafx.scene.paint.Color;
- import javafx.scene.shape.Circle;
- import javafx.stage.Stage;
- public class Kreis extends Application {
- HBox hbButton;
- Button bMalen;
- StackPane leinwand;
- Circle kreis;
- @Override
- public void start(Stage primaryStage) throws Exception {
- erstelleButton();
- erstelleAktion();
- leinwand = new StackPane();
- BorderPane root = new BorderPane();
- root.setCenter(leinwand);
- root.setBottom(hbButton);
- Scene scene = new Scene(root, 300, 400);
- primaryStage.setScene(scene);
- primaryStage.setTitle("bunte Kreise");
- primaryStage.show();
- }
- public static void main(String[] args) {
- launch(args);
- }
- //Hilfsmethoden
- private void erstelleButton() {
- hbButton = new HBox();
- hbButton.setPadding(new Insets(10));
- hbButton.setSpacing(5);
- hbButton.setAlignment(Pos.CENTER);
- hbButton.setBackground(new Background(new BackgroundFill(Color.DARKGRAY, null, null)));
- bMalen = new Button("malen");
- hbButton.getChildren().add(bMalen);
- }
- private void erstelleAktion() {
- bMalen.setOnAction(e ->{
- Random r = new Random();
- leinwand.getChildren().clear();
- Color c = new Color(r.nextDouble(),r.nextDouble(),r.nextDouble(),1.0);
- kreis = new Circle(100,100,50, c);
- leinwand.getChildren().add(kreis);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement