Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My teacher has presented me with 4 related programming questions as part of an e

ID: 3760769 • Letter: M

Question

My teacher has presented me with 4 related programming questions as part of an exercise on stage/pane programming. This is my assignment:

In the next two programs, a blue circle is displayed. Whenever the mouse is clicked, it will move to that location.

1) Fill in the missing code below that registers the ClickHandler class for click instances in pane "p".

2) Fill in the missing code below for the ClickHandler class that moves the circle to the position of the click.

In the last two questions, the program displays a rectangle. When the window size is changed, the rectangle also changes in size.

3) Fill in the missing code that will bind the height of the rectangle "rectangle" to one half the height of pane p, and will also bind the width to one half the width of pane p.

4) Fill in the missing code that sets the fill color of "rectangle" to alice blue, sets the outline color of "rectangle" to yellow green and sets the outline width of "rectangle" to 5.

Thank you very much.

Explanation / Answer

Answer:

Note: Code modified I solved the first and second Question

Answer 1:

import javafx.application.Application;

import javafx.event.EventHandler;

import javafx.scene.Scene;

import javafx.scene.input.MouseEvent;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

public class FirstQuestion extends Application

{

    private Circle circle;

    public void start(Stage primaryStage) throws Exception

{

        Pane p = new Pane();

        circle = new Circle( 50, 50, 20, Color.ALICEBLUE);

        p.getChildren().add(circle);

p.setCenter(p);

p.setBottom(p);

p.setSize(500,400);

p.setTitle("Circle");

Scene sc = new Scene(p, 500, 500);

        primaryStage.setScene(sc);

        primaryStage.setTitle("Question 1");

          primaryStage.show();

    }

}

Answer 2:

import javafx.application.Application;

import javafx.event.EventHandler;

import javafx.scene.Scene;

import javafx.scene.input.MouseEvent;

import javafx.scene.layout.Pane;

import javafx.scene.paint.Color;

import javafx.scene.shape.Circle;

import javafx.stage.Stage;

public class SecondQuestion extends Application {

    private Circle circle;

    private class ClickHandler implements EventHandler<MouseEvent> {

        public void handle(MouseEvent event)

{

        }

    }

}