In: Computer Science
Please find the code below:
RandomCirclesWithLargestDiff.java
package gui;
import java.util.Random;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class RandomCirclesWithLargestDiff extends Application
{
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new
Group(), 1000, 1000);
Group rowCircle = (Group)
scene.getRoot();
Random rand = new Random();
Circle largest=null;
for(int i=0;i<10;i++){
Circle circle =
new
Circle(rand.nextInt(1000),rand.nextInt(1000),rand.nextInt(100));
if(largest==null){
largest =circle;
}else
if(largest.getRadius()<circle.getRadius()){
largest = circle;
}
circle.setStroke(Color.BLACK);
circle.setFill(Color.TRANSPARENT);
rowCircle.getChildren().add(circle);
}
largest.setOpacity(0.3);
largest.setFill(Color.RED);
primaryStage.setScene(scene);
primaryStage.show();
}
}
output: