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

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 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...
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...
in a gui ' in java write a program that draws equal a simple fence with...
in a gui ' in java write a program that draws equal a simple fence with vertical, spaced slats backed by two boards. Behind the fence show a simple house support Make sure the in the und. house is visible between the slats in the fence.
(Display a Circle and Its Attributes) Write a program that displays a circle of random size...
(Display a Circle and Its Attributes) Write a program that displays a circle of random size and calculates and displays the area, radius, diameter and circumference. Use the following equations: diameter = 2 × radius, area = π × radius2, circumference = 2 × π × radius. Use the constant Math.PI for pi (π). All drawing should be done on a subclass of JPanel, and the results of the calculations should be displayed in a read-only JTextArea.
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It...
1. write a program for the msp430fr6989 that will light LED1, whenever S1 is pressed. It should turn off whenever S1 is released. 2. Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT