Question

In: Computer Science

(Not in Swing) Write a JavaFX application that creates polyline shapes dynamically using mouse clicks. Each...

(Not in Swing)

Write a JavaFX application that creates polyline shapes dynamically using mouse clicks.

Each mouse click adds a new line segment to the current polyline from the previous point to the current mouse position. Allow the user to end the current polyline with the double click. Also, provide a button that clears the window and allows the user to begin again.

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

Javafx - polyline with Examples :

Polyline is component of the JavaFX library. Polyline is a set of correlated points. Even Though Polyline is almost similar to the Polygon class, the only variation is polygon forms a closed area whereas the Polyline can form both closed and open area. Also, Polyline class expands shape class.

Constructors for class are

· Polyline():Creates an empty instance of Polyline.

· Polyline(double… points): creates a new instance of polyline with given points

Commonly used methods:

METHOD

Explanation

getPoints()

Gets the points of the polyline segments

toString()

Returns a string representation of this polyline project.

iiiiiiiiiiiiiiiprogramsishowitheiusageiofiPolyline:

I. iiiiiiiiiiiiiSystemitoicreateianiopeniareaiofilinkedisectionsiusingipolyline:iThisiprogramimakesiaiPolylineiindicatedibyitheinameipolyline.itheimanagesiofitheipointsiofitheilineisegmentsitoicreateianiopeniarea.iTheiPolylineiwillibeicreatediwithiniaiscene,iwhichiiniturniwillibeihostediinsideiaistage.iTheifunctionisetTitle()iisiuseditoiprovideititleitoitheistage.iTheniaiGroupiisicreated,ianditheipolylineiisiconnected.iTheigroupiisiconnecteditoitheiscene.iLastly,itheishow()imethodiisicalleditoishowitheifinaliresults.i

iiiiiiiiiiiiiMessagei:TheiaboveiprogramsimightinotiruniinianionlineiIDEipleaseiuseianiofflineiconverter....

II. JavaiProgramitoicreateianiopeniareaiofilinkedisectionsiusingipolyline

  

import javafx.application.Application;

import javafx.scene.Scene;

  import javafx.scene.control.Button;

import javafx.scene.layout.*;

import javafx.scene.paint.Color;

import javafx.scene.shape.Polyline;

import javafx.scene.control.*;

import javafx.stage.Stage;

import javafx.scene.Group;

public class Polyline_0 extends Application

{

public void start(Stage stage) // launch the application

{

stage.setTitle("creating Polyline"); // set title for the stage

double points[] = { 20.0d, 20.0d, 40.0d, 240.0d, 60.0d,

                          180.0d, 80.0d, 200.0d, 100.0d, 90.0d }; // points

Polyline polyline = new Polyline(points);   // create a polyline

Group group = new Group(polyline); // create a Group

Scene scene = new Scene(group, 500, 300); // create a scene

stage.setScene(scene); // set the scene

stage.show();

}

public static void main(String args[])

{

launch(args); // launch the application

}

}

III.iiiiprogramitoibuildiaiclosediareaiofilinkedisectionsiusingipolyline:iThisiprogramimakesiaiPolylineishowedibyitheinameipolylineitheicoordinatesiofitheipointsiofitheilineisegmentsitoicreateiaiclosediarea.iTheiPolylineiwillibeigeneratediwithiniaiscene,iwhichiiniturniwillibeipresentediwithiniaistage.iTheifunctionisetTitle()iisiuseditoirequireititleitoitheistage.iTheniaiGroupiisicreated,ianditheipolylineiisiattached.iTheigroupiisiattacheditoitheiscene.iFinally,itheishow()imethodiisicalleditoishowitheifinaliresults.filter_none

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.layout.*;

import javafx.scene.paint.Color;

import javafx.scene.shape.Polyline;

import javafx.scene.control.*;

import javafx.stage.Stage;

import javafx.scene.Group;

public class Polyline_1 extends Application

{

public void start(Stage stage)   // launch the application

{

stage.setTitle("creating Polyline");   // set title for the stage

double points[] = { 20.0d, 20.0d, 40.0d, 240.0d, 60.0d,

180.0d, 80.0d, 200.0d, 100.0d, 90.0d, 20.0d, 20.0d };     // points

Polyline polyline = new Polyline(points); // create a polyline

Group group = new Group(polyline);         // create a Group

Scene scene = new Scene(group, 500, 300);         // create a scene

stage.setScene(scene); // set the scene

stage.show();

}

public static void main(String args[])

{

launch(args); // launch the application

}

}


Related Solutions

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.
In Java and using JavaFX, write a client/server application with two parts, a server and a...
In Java and using JavaFX, write a client/server application with two parts, a server and a client. Have the client send the server a request to compute whether a number that the user provided is prime. The server responds with yes or no, then the client displays the answer.
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes...
C++ Write a program that creates two rectangular shapes and then animates them. The two shapes should start on opposite ends of the screen and then move toward each other. When they meet in the middle of the screen, each shape reverses course and moves toward the edge of the screen. The two shapes keep oscillating and bouncing off of each other in the middle of the screen. The program terminates when the shapes meet each other in the middle...
Using NetBeans IDE, write a JavaFX application that allows theuser to choose insurance options. Use...
Using NetBeans IDE, write a JavaFX application that allows the user to choose insurance options. Use a ToggleGroup to allow the user to select only one of two insurance types—HMO (health maintenance organization) or PPO (preferred provider organization). Use CheckBoxes for dental insurance and vision insurance options; the user can select one option, both options, or neither option. As the user selects each option, display its name and price in a text field; the HMO costs $200 per month, the...
C# Create a console application named that creates a list of shapes, uses serialization to save...
C# Create a console application named that creates a list of shapes, uses serialization to save it to the filesystem using XML, and then deserializes it back: // create a list of Shapes to serialize var listOfShapes = new List<Shape> { new Circle { Colour = "Red", Radius = 2.5 }, new Rectangle { Colour = "Blue", Height = 20.0, Width = 10.0 }, new Circle { Colour = "Green", Radius = 8 }, new Circle { Colour = "Purple",...
Write a JavaFX application that presents two buttons and a number (initially 50) to the user....
Write a JavaFX application that presents two buttons and a number (initially 50) to the user. Label the buttons Increment and Decrement. When the increment button is pushed, increment the displayed value. Likewise, decrement the value when the decrement button is pushed. This has to use Java.Fx and not Java.Awt
Write a JavaFX application that displays a Label containing the opening sentence or two from your...
Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b // FXBookQuote1a.java import javafx.application.Application; import static javafx.application.Application.launch; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.Pane; import javafx.scene.text.Font; import javafx.stage.Stage; public class FXBookQuote1a...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing...
Create an application to simulate a bank ATM and you must combine graphical interfaces using Swing or AWT and relational databases. We will have a Bank Accounts database. Each account will have an account number, the name of the owner and the account balance. The program must allow the following options: a) Create an account: request the account information and save it in the database. b) Enter the ATM: it will allow you to request the account number and will...
Write an application, Phone Numbers, that creates and prints a random phone number of the form...
Write an application, Phone Numbers, that creates and prints a random phone number of the form XXX-XXX-XXXX. Include the dashes in the output. The phone number has some constraints. Do not let the first three digits contain an 3 or 7 (but do not be more restrictive than that) and ensure that the second set of three digits is not greater than 825. Note that any of the digits can be zero and zeroes should be shown.
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8. there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT