Question

In: Computer Science

Write a program that draws a fixed circle centered at (100, 60) with radius 50. Whenever...

Write a program that draws a fixed circle centered at (100, 60) with radius 50. Whenever the mouse is moved, display a message indicating whether the mouse point is inside the circle at the mouse point or outside of it. Write in Java please.

Solutions

Expert Solution

JAVA CODE:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.*;


public class CircleEx extends Application
{
   //overriding the start method in the application class
   @Override
  
   public void start(Stage ps)
   {
       // creating the pane
       Pane p = new Pane();

       // creating cirle with specified properties
       Circle c = new Circle(100, 60, 50);
       c.setFill(Color.CYAN);
       c.setStroke(Color.RED);
       p.getChildren().add(c);

       // registering the handle
       p.setOnMouseMoved(mouseevent -> {
          
           p.getChildren().clear();          
          
           Text t = new Text(mouseevent.getX(), mouseevent.getY(), "Mouse pointer is now " +
               (c.contains(mouseevent.getX(), mouseevent.getY()) ? "inside " : "outside ") +
               "the circle");
           p.getChildren().addAll(c, t);
       });

       // creating the scene
       Scene sc = new Scene(p, 350, 150);
      
       //setting the stage title
       ps.setTitle("Circle Exercise");
      
       //placing the scene in the stage
       ps.setScene(sc);
      
       //displaying the stage
       ps.show();
   }
  
  
}

SCREENSHOT FOR OUTPUT:


Related Solutions

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...
Write a program that draws the circumscribed circle (also known as the circumcircle) of a given...
Write a program that draws the circumscribed circle (also known as the circumcircle) of a given triangle ABC; this circle passes through points A, B, and C. These points will be specified by the user by clicking the mouse button. Remember, the three perpendicular bisectors of the three edges of a triangle all pass through one point, the circumcenter, which is the center of the circumscribed circle.
Write a program that draws the circumscribed circle (also known as the circumcircle) of a given...
Write a program that draws the circumscribed circle (also known as the circumcircle) of a given triangle ABC; this circle passes through points A, B, and C. These points will be specified by the user by clicking the mouse button. Remember, the three perpendicular bisectors of the three edges of a triangle all pass through one point, the circumcenter, which is the center of the circumscribed circle.
Write a C++ program that prompts the user for the radius of a circle and then...
Write a C++ program that prompts the user for the radius of a circle and then calls inline function circleArea to calculate the area of that circle. It should do it repeatedly until the user enters -1. Use the constant value 3.14159 for π Sample: Enter the radius of your circle (-1 to end): 1 Area of circle with radius 1 is 3.14159 Enter the radius of your circle (-1 to end): 2 Area of circle with radius 2 is...
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 c code program for the following Write a function, circle, which takes the radius of...
Write c code program for the following Write a function, circle, which takes the radius of a circle from the main function and assign the area of the circle to the variable, area, and the perimeter of the circle to the variable, perimeter. Hint: The function should have three variables as input. Since the contents of the variables are to be modified by a function, it is necessary to use pointers. Please type out the full usable program. Thank you.
Write a program, circleref.cpp, that inputs a double radius of circle. It should print, given this...
Write a program, circleref.cpp, that inputs a double radius of circle. It should print, given this radius, the circumference of the circle, the area of the circle, the surface area of a sphere with that radius and the area of a sphere with that radius. Each of its computation functions returns its answers in call by reference parameters. Here are the formulas for computation: Circumference = 2 • π • r Circle Area = π • r2 Sphere Surface Area...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels,...
Write a Java program named CircleZapper that displays a circle with a radius of 10 pixels, filled with a random color at a random location on the screen. When you click the circle, it disappears and a new random color circle is displayed at another random location (see display below). After twenty circles are clicked, display the time spent in the pane. To detect whether a point is inside the circle, use the contains method defined in the Node class....
1.) Build the parametric equations of a circle centered at the point (2,-3) with a radius...
1.) Build the parametric equations of a circle centered at the point (2,-3) with a radius of 5 that goes counterclockwise and t=0 gives the location (7,-3) 2.) Build the parametric equations for an ellipse centered at the point (2, -3) where the major axis is parallel to the x-axis and vertices at (7, -3) and (-3, -3), endpoints of the minor axis are (2, 0) and (2, -6). The rotation is counterclockwise 3.) Build the parametric equations for a...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT