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

PLEASE READ CAREFULLY STEP BY STEP I NEED IT TO STUDY FOR FINALS Lab Exercise 15

ID: 3832313 • Letter: P

Question

PLEASE READ CAREFULLY STEP BY STEP I NEED IT TO STUDY FOR FINALS

Lab Exercise 15b CIT239 Java Programming Display Points This lab exercise is adapted from Programming Exercise 15.15. Due Date You must demonstrate the solution for this lab exercise to the instructor by Sunday, December 6, 2015, in order to receive credit for this work. Add Remove Points on a Display Write a JavaFX application that lets the user click on a pane to dynamically create and remove points. When the user left-clicks the mouse (PRIMARY button), a point is created and displayed at the mouse point. The user can remove a point by pointing to it and right-clicking the mouse (SECONDARY button). Lab15b A suitable way to draw the "points" is to make each point a Circle object with radius 5 pixels (see http://docs racle. comiavafx/2/apilindex.html HINT: Remember that the list of nodes displayed in a JavaFX application can be accessed with code such as the following: Observable List Node> list pane .get Children for (int i 0; i K list.size it+) System.out.printf i d, n sln", i, list .get (i tostring ode Also remember that you can access the nodes in an observableList in a similar manner to an ArrayList. CIT239-SU Lab15b Display Points, 20151122. docx 4/1/2017 8:28 PM 1 of 2

Explanation / Answer

import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;


public class Lab15b extends Application
{
    @Override public void start(Stage primaryStage)
    {
        Pane pane = new Pane();
        pane.setPrefSize(480, 320);

        pane.setOnMouseClicked(e ->
        {
            if(e.getButton().equals(MouseButton.PRIMARY))
            {
                Circle circle = new Circle(5);
                circle.setStroke(Color.BLACK);
                circle.setFill(Color.AQUA);
                circle.setCenterX(e.getX());
                circle.setCenterY(e.getY());

                pane.getChildren().add(circle);

                System.out.printf("Adding point at x=%6.1f, y=%6.1f ", e.getX(), e.getY());
            }
            if(e.getButton().equals(MouseButton.SECONDARY))
            {
                ObservableList<Node> list = pane.getChildren();

                for(int i = 0; i < list.size(); i++)
                {
                    if(list.get(i).contains(e.getX(), e.getY()))
                    {
                        pane.getChildren().remove(i);
                        System.out.printf("Removing point at x=%6.1f, y=%6.1f ", e.getX(), e.getY());
                        break;
                    }
                }
            }
        });

        Scene scene = new Scene(pane);
        primaryStage.setScene(scene);
        primaryStage.setTitle("Lab15b");
        primaryStage.show();
    }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote