Question

In: Computer Science

Write a JavaFX application that draws 10 circles of random radius in random locations. Leave all...

Write a JavaFX application that draws 10 circles of random radius in random locations. Leave all circles unfilled except for the largest circle which should be filled with a translucent red (30% opaque) . If multiple circles have the same largest size, fill any one of them. Hint: keep track of the largest circle as you generate them, then change fill to red. Thankuou

Solutions

Expert Solution

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:


Related Solutions

In Java, Write a JavaFX application that draws multiple circles using a rubberbanding technique. The circle...
In Java, Write a JavaFX application that draws multiple circles using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.Thank you and could you also show the finished product?
Write a JavaFX application that draws 5 squares. Use a random number generator to generate random...
Write a JavaFX application that draws 5 squares. Use a random number generator to generate random values for the size, x, and y. Make the size between 100 and 200, x between 0 and 600, y between 0 and 400. You can pick any color, but you must use different colors for the 5 squares. Set your window to 600 by 400.
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is...
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag. Use the initial mouse press location as the fixed center point of the circle. Compute the distance between the current location of the mouse pointer and the center point to determine the current radius of the circle.
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius....
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle's radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write portions of codes which calculates the circle's area and the square's...
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius....
In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s radius. A respective square whose diagonal is the circle's diameter can then be created. There are three other controls in this application: a button(btCalculate), two textareas(trCircleArea, trSquareArea). When the button is clicked, the circle's area is calculated and displayed on trCircleArea, furthermore, the square's area is also calculated and displayed on trSquareArea. Please write the portions of codes which calculates the circle’s area and the...
Write a JavaFX application that presents a button and a circle. Every time the button is...
Write a JavaFX application that presents a button and a circle. Every time the button is pushed, the circle should be moved to a new random location within the window. This must only be one .java file. I cannot use import javafx.geometry.Insets; import javafx.scene.canvas.Canvas; import javafx.scene.canvas.GraphicsContext; import javafx.scene.layout.HBox; This is what I have so far: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.shape.Circle; import javafx.scene.paint.Color; import javafx.stage.Stage; public class CircleJumper extends Application...
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
Java Write a JavaFX application that displays a button and a number. Every time the button...
Java Write a JavaFX application that displays a button and a number. Every time the button is pushed, change the number to a random value between 1 and 100. Thank you and can you show a picture of the result as well
Write a JavaFX application that displays a Label containing the opening sentence or two from your...
Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b // FXBookQuote1a.java import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.stage.Stage; public class FXBookQuote1a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT