This task is a program framework that you should complete. The program should allow the user to move a circular figure with the mouse over a drawing area. The current position of the figure is displayed continuously:

Given is the main program:
import javafx.scene.Scene;
import javafx.application.Application;
import javafx.beans.value.*;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
private DraggableCircle dc;
private Text text;
private void updateText() {
text.setText("("+dc.getCenterX()+", "+dc.getCenterY()+")");
}
@Override
public void start(final Stage stage) throws Exception {
dc= new DraggableCircle(100d, 100d);
text= new Text(10, 10, "");
updateText(); // initialize once
// TODO: create a ChangeListener<Number>, that is
// called everytime the user moved the "dc" center coordinates.
// The change listener should call the above updateText method.
//
// Hint: add the ChangeListener to both of dc's
// centerXProperty and centerYProperty.
// Please insert your code here ...
Group root = new Group(dc, text);
stage.setScene(new Scene(root, 400, 400, Color.ALICEBLUE));
stage.setTitle("Drag Sample");
stage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
At the marked point, code should be added by you.
Furthermore, the DraggableCircle class printed below is given, which represents the object to be moved. The class inherits from the JavaFX class javafx.scene.shape.Circle, whose function you might want to look at first by consulting the API documentation.
The constructor of the DraggableCircle class creates a yellow
disk at the position specified by the constructor parameters. In
addition, the constructor already implements an EventHandler, which
displays the following icon as a mouse pointer when the mouse
button is pressed:
import javafx.scene.Cursor;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.StrokeType;
class DraggableCircle extends Circle {
DraggableCircle(double x, double y) {
super(x, y, 10);
setFill(Color.YELLOW);
setStroke(Color.GOLD);
setStrokeWidth(2);
setStrokeType(StrokeType.OUTSIDE);
setOnMousePressed( ev -> {
getScene().setCursor(Cursor.MOVE);
});
// TODO: implement event handlers as follows:
// - mouse button releases: show default cursor
// - mouse dragged: set the center of the circle to the
current
// mouse position.
}
}
They should now complete the class. First a corresponding EventHandler has to be implemented, which returns the mouse pointer to the default when the mouse button is released. In addition, you should program the drawing of the circular disk. Please note the following solution idea:
One or more instance attributes to be implemented by you pick up
the mouse pointer position when the mouse button is pressed
down.
When the user starts moving the mouse, MOUSE_DRAGGED MouseEvents
will be generated continuously.
Each mouseDragged event calls an event handler you want to write
that queries the current mouse position.
The coordinates of the two current mouse positions are used by this
EventHandler to reposition the circular disc with setCenterX or
setCenterY.
To get a "nice" result, you need to think about how you can prevent
the disc from "jumping" if the user does not press down the mouse
button right in the center of the disc. In this case, when the
mouse button is pressed down, there is an "offset" between the
circle center and the mouse position. This offset should be
maintained throughout the shift operation.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
// Main.java
import javafx.scene.Scene;
import javafx.application.Application;
import javafx.beans.value.*;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Main extends Application {
private DraggableCircle dc;
private Text text;
private void updateText() {
text.setText("(" + dc.getCenterX() + ", " + dc.getCenterY() + ")");
}
@Override
public void start(final Stage stage) throws Exception {
dc = new DraggableCircle(100d, 100d);
text = new Text(10, 20, "");
updateText(); // initialize once
//adding change listener for center x property of dc
dc.centerXProperty().addListener(e -> {
//updating text
updateText();
});
//adding change listener for center y property of dc
dc.centerYProperty().addListener(e -> {
updateText();
});
Group root = new Group(dc, text);
stage.setScene(new Scene(root, 400, 400, Color.ALICEBLUE));
stage.setTitle("Drag Sample");
stage.show();
}
public static void main(String[] args) throws Exception {
launch(args);
}
}
// DraggableCircle.java
import javafx.scene.Cursor;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.StrokeType;
class DraggableCircle extends Circle {
private double offsetX, offsetY; //offset values
DraggableCircle(double x, double y) {
super(x, y, 10);
setFill(Color.YELLOW);
setStroke(Color.GOLD);
setStrokeWidth(2);
setStrokeType(StrokeType.OUTSIDE);
setOnMousePressed(ev -> {
getScene().setCursor(Cursor.MOVE);
//recording offset values (change of point of press with respect
//to the center coordinates)
offsetX=ev.getX()-getCenterX();
offsetY=ev.getY()-getCenterY();
});
setOnMouseReleased(ev->{
//using default cursor icon
getScene().setCursor(Cursor.DEFAULT);
});
//adding mouse dragged listener
setOnMouseDragged(ev->{
//setting center coordinates to current position of mouse, with respect
//to the offset values
setCenterX(ev.getX()-offsetX);
setCenterY(ev.getY()-offsetY);
});
}
}
/*OUTPUT*/

This task is a program framework that you should complete. The program should allow the user...
In Java.
Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...
For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...
JAVA SOLUTION This lab has four parts: Create a window. Create 5 buttons in that window. Create an event when a button is pushed. Create an event listener that will respond to the button being pushed event. Task 1 – Create a Window For Java: Please ensure that the following import statements are used: import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.GridPane; import javafx.scene.text.Text; import javafx.event.EventHandler; import javafx.scene.input.MouseEvent; Next, ensure that there is a main method which is...
I mainly need help with the “Mouse Events” & “Command
Buttons” sections
Sqrt xA2 Cir CircleButton Clas:s The graphic circular buttons are created by drawing a filled Circle on a StackPane. So, the pictured GUI uses 9 different StackPanes tor displaying the 9 qraphic buttons. Of course, these CircleButton objects can then be placed on a single GridPane lo achieve the 3x3 layoul (see SimpleCalc class below). Creale a class narned CircleBullon thal exlends the StackPane class. The class should...
DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...
" In the workshop exercises you have used Python's Tkinter module to create simple Graphical User Interfaces. The following code is an incomplete Python program relying on Tkinter (with deliberately unhelpful variable and function names) which you must complete by filling in the blanks. When complete the program should create a window with two buttons, labelled and!!', respectively. When the button la belled'???' is pushed nothing happens. When the button labelled'!!"is pushed both buttons' labels are set to'!!!' from tkinter...
(C++ Program) 1. Write a program to allow user enter an array of structures, with each structure containing the firstname, lastname and the written test score of a driver. - Your program should use a DYNAMIC array to make sure user has enough storage to enter the data. - Once all the data being entered, you need to design a function to sort the data in descending order based on the test score. - Another function should be designed to...
Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...
##JAVA## about a GUI program (see screenshot below) that
permits the user to create, save, and load polygons that are
displayed (both hollow and filled) in a GUI. The features and
operations required by the GUI program include:
1. The program starts with an empty (no vertices) polygon set
with a randomly generated color. The drawing area is set to be
initially square and should have a black background.
------------------------------------------------------------------------------------------------
2. The left mouse button lets you begin building a...
15.3 (Move the ball) Write a program that moves the ball in a pane. You should define a pane class for displaying the ball and provide the methods for moving the ball left, right, up, and down, as shown in Figure 15.24c. Check the boundary to prevent the ball from moving out of sight completely. import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Driver extends Application...