Question

In: Computer Science

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?

Solutions

Expert Solution

Please find the code below:

DrawCircleOnDragWithRadius.java

package gui;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class DrawCircleOnDragWithRadius extends Application {
   double startingX,endingX;
   double startingY,endingY;
   Circle circle;
   boolean start;
   @Override
   public void start(Stage primaryStage) {
       Group root = new Group();
       Scene scene = new Scene(root, 1000, 1000);
       scene.setOnMouseDragged((t) -> {
           if(start){
               startingX = t.getSceneX();
               startingY = t.getSceneY();
               circle.setCenterX(startingX);
               circle.setCenterY(startingY);
               start = false;
           }
           double dist = Math.sqrt(Math.pow(startingX-t.getSceneX(), 2)+Math.pow(startingY-t.getSceneY(), 2));
           circle.setRadius(dist);
       });
       circle = new Circle(0,0,0);
       scene.setOnMouseClicked((t) -> {
           start = true;
       });
       start = true;
       root.getChildren().add(circle);
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}

output:


Related Solutions

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.
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
In java processing 3, write a program that draws a circle. The center of the circle...
In java processing 3, write a program that draws a circle. The center of the circle would be first point on the canvas where the mouse is pressed on it. While the mouse is pressed, the circle can be drawn by moving the mouse cursor farther than the first point that mouse was pressed (circle center). As soon as the code is run, a timer at the bottom of the canvas should start working. Also, the radius of the circle...
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.
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 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.
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 multiple stage application which has at least two stages, a primary one and a secondary one.
JavaFX Two-Stage ApplicationWrite a JavaFX multiple stage application which has at least two stages, a primary one and a secondary one.The primary stage should have a gridpane which has at least a 2*3 grid.On each cell of the grid, please place a different node from at least one of the three types: a UI control or a shape or an image view, etc.On the secondary stage, you should design a layout with binding property.Your overall project design should reflect a...
Java In a JavaFX application there is a TextField control(tfRadius) for taking input of a circle’s...
Java 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...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT