Advertisement
iTzChr1stmasX

Untitled

Jul 7th, 2019
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.71 KB | None | 0 0
  1. package klausur;
  2.  
  3. import java.util.Random;
  4.  
  5. import javafx.application.Application;
  6. import javafx.geometry.Insets;
  7. import javafx.geometry.Pos;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.Button;
  10. import javafx.scene.layout.Background;
  11. import javafx.scene.layout.BackgroundFill;
  12. import javafx.scene.layout.BorderPane;
  13. import javafx.scene.layout.HBox;
  14. import javafx.scene.layout.StackPane;
  15. import javafx.scene.paint.Color;
  16. import javafx.scene.shape.Circle;
  17. import javafx.stage.Stage;
  18.  
  19. public class Kreis extends Application {
  20.     HBox hbButton;
  21.     Button bMalen;
  22.     StackPane leinwand;
  23.     Circle kreis;
  24.    
  25.  
  26.     @Override
  27.     public void start(Stage primaryStage) throws Exception {
  28.         erstelleButton();
  29.         erstelleAktion();
  30.         leinwand = new StackPane();
  31.         BorderPane root = new BorderPane();
  32.         root.setCenter(leinwand);
  33.         root.setBottom(hbButton);
  34.         Scene scene = new Scene(root, 300, 400);
  35.        
  36.         primaryStage.setScene(scene);
  37.         primaryStage.setTitle("bunte Kreise");
  38.         primaryStage.show();
  39.  
  40.     }
  41.  
  42.     public static void main(String[] args) {
  43.         launch(args);
  44.  
  45.     }
  46.    
  47.     //Hilfsmethoden
  48.    
  49.     private void erstelleButton() {
  50.         hbButton = new HBox();
  51.         hbButton.setPadding(new Insets(10));
  52.         hbButton.setSpacing(5);
  53.         hbButton.setAlignment(Pos.CENTER);
  54.         hbButton.setBackground(new Background(new BackgroundFill(Color.DARKGRAY, null, null)));
  55.         bMalen = new Button("malen");
  56.         hbButton.getChildren().add(bMalen);
  57.     }
  58.    
  59.     private void erstelleAktion() {
  60.         bMalen.setOnAction(e ->{
  61.             Random r = new Random();
  62.             leinwand.getChildren().clear();
  63.             Color c = new Color(r.nextDouble(),r.nextDouble(),r.nextDouble(),1.0);
  64.             kreis = new Circle(100,100,50, c);
  65.             leinwand.getChildren().add(kreis);
  66.            
  67.         });
  68.        
  69.    
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement