JavaFx-Random

Program

JavaFx-Random

 

JavaFx-Random

Program Source

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Line;
import javafx.scene.shape.StrokeLineCap;
import javafx.scene.paint.Color;
import java.util.Random;

public class JavaFXApplication extends Application {
    
   
    public static void main(String[] args) {
        
       Application.launch(args);
    }
    
    public void start(Stage primaryStage) {
        
        primaryStage.setTitle("Random");
        Group root = new Group();
        Scene scene = new Scene(root, 700, 200, Color.GRAY);
        
        Random rand = new Random(System.currentTimeMillis());
        for (int i = 0; i < 100; i++) {
            int red = rand.nextInt(255);
            int green = rand.nextInt(255);
            int blue = rand.nextInt(255);
            
            Line line = new Line(200, 50, 50, 150);
            int rot = rand.nextInt(360);
            line.setRotate(rot);
            line.setStrokeLineCap(StrokeLineCap.ROUND);
            line.setStrokeWidth(10);
            line.setStroke(Color.rgb(red, green, blue, .99));
            root.getChildren().add(line);
        }
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

One thought on “JavaFx-Random

Leave a Comment