Q2 Write a JavaFX program that displays a rectangle with upper-left corner point at (40, 40), width 40, and height 60. Display a circle with radius 30 centered at the mouse point when the mouse is clicked. Display a text to indicate whether the circle contains, intersects, or is outside of the rectangle, as shown in Figure 3. Create the GUI programmatically. DO not use FXML.
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class CircleInstersectRectangle extends Application
{
private Rectangle rectangle;
private Circle circle;
private Label text;
private boolean isContaining = false, isIntersecting = false;
@Override
public void start(Stage primaryStage) {
Group mainGroup = new Group();
Group drawGroup = new Group();
Group textGroup = new Group();
text = new Label("None");
rectangle = new Rectangle(40, 40, 40, 60);
rectangle.setFill(Color.TRANSPARENT);
rectangle.setStroke(Color.RED);
rectangle.setStrokeWidth(1);
textGroup.getChildren().add(text);
drawGroup.getChildren().add(rectangle);
mainGroup.getChildren().addAll(drawGroup, textGroup);
Scene scene = new Scene(mainGroup, 400, 250);
scene.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent
mouseEvent) -> {
if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
circle = new Circle(mouseEvent.getX(), mouseEvent.getY(), 30,
Color.BLUE);
addEventHandler(drawGroup, circle);
drawGroup.getChildren().add(circle);
// change the text
int rectCenterX = 60;
int rectCenterY = 70;
if(mouseEvent.getX() == rectCenterX && mouseEvent.getY() ==
rectCenterY)
{
text.setText("Circle is inside the rectangle!");
}
else if((mouseEvent.getX() + 30 >= 70 &&
mouseEvent.getX() + 30 <= 110)
&& (mouseEvent.getX() + 30 >= 70 &&
mouseEvent.getX() + 30 <= 130))
{
text.setText("Circle is intersecting the rectangle!");
}
else if((mouseEvent.getX() + 30 < 40 || mouseEvent.getX() + 30
> 110)
&& (mouseEvent.getX() + 30 < 40 || mouseEvent.getX() +
30 > 130))
{
text.setText("Circle is outside the rectangle!");
}
}
});
primaryStage.setTitle("Circle & Rectangle!");
primaryStage.setScene(scene);
primaryStage.show();
}
public void addEventHandler(Group parent, Node node)
{
node.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent
mouseEvent) -> {
if (mouseEvent.getButton().equals(MouseButton.SECONDARY)) {
parent.getChildren().remove(node);
text.setText("None");
}
});
}
public static void main(String[] args) {
launch(args);
}
}
Q2 Write a JavaFX program that displays a rectangle with upper-left corner point at (40, 40), wid...
PP.14
PP 3.13 Write a JavaFX application that draws a circle centered at poinit (200, 200) with a random radius in the range 50 to 150. Each time the program is run it will draw a different circle. PP 3.14 Write a JavaFX application that displays your name rotated at a random angle (0 to 360). Each time the program is run it will draw your name at a different angle. a random color created using the rgb method of...
PP.15
PP 3.13 Write a JavaFX application that draws a circle centered at poinit (200, 200) with a random radius in the range 50 to 150. Each time the program is run it will draw a different circle. PP 3.14 Write a JavaFX application that displays your name rotated at a random angle (0 to 360). Each time the program is run it will draw your name at a different angle. a random color created using the rgb method of...
(PYTHON) Write a program that displays the following menu:. , Write Algorithm for Code Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1 - 4): If the user enters 1, the program should ask for the radius of the circle and then display its area. If the user enters 2, the program should ask for the length and width of...
Geometric calclator use python to do this program. Write a program that displays the following menu: 1. Calculate the area of circle 2. calculate the area of rectangle 3. calculate the area of triangle 4. Quit Enter your choice (1-4). if the user enters 1, your program should ask for the radius of the circle and then display its area. Use the formula to calculate the circle's area: Area = pi*r^2 Use 3.14149 for Pi and the radius of the...
Java only please Write a program that displays the following menu: Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Triangle 3. Calculate the Area of a Rectangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use the formula: area = ∏r2 Use 3.14159 for ∏. If the user enters 2 the program should ask for...
Within NetBeans, write a Java program for EACH of the following problems. (The Rectangle class) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: · Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. · A no-arg constructor that creates a default rectangle. · A constructor that creates a...
Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...
Its java class pratice problem (Geometry: point in a rectangle?) Write a program that prompts the user to enter a point (x, y) and checks whether the point is within the rectangle centered at (0, 0) with width 10 and height 5. For example, (2, 2) is inside the rectangle and (6, 4) is outside the rectangle. (Hint: A point is in the rectangle if its horizontal distance to (0, 0) is less than or equal to10 / 2 and...
Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...
Modify the NervousShapes program so that it displays equilateral
triangles as well as circles and rectangles. You will need to
define a Triangle class containing a single instance variable,
representing the length of one of the triangle’s sides. Have the
program create circles, rectangles, and triangles with equal
probability. Circle and Rectangle is done, please comment on your
methods so i can understand
*/
package NervousShapes;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import javax.swing.event.*;
public class...