Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Customize the program from Chapter 15. Make sure you include the changes you had made to the program in your Program Purpose and Customization. import

Customize the program from Chapter 15. Make sure you include the changes you had made to the program in your Program Purpose and Customization.

import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; 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.text.Text; import javafx.stage.Stage;

public class AnonymousHandlerDemo extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Text text = new Text(40, 40, "Programming is fun"); Pane pane = new Pane(text); // Hold four buttons in an HBox Button btUp = new Button("Up"); Button btDown = new Button("Down"); Button btLeft = new Button("Left"); Button btRight = new Button("Right"); HBox hBox = new HBox(btUp, btDown, btLeft, btRight); hBox.setSpacing(10); hBox.setAlignment(Pos.CENTER); BorderPane borderPane = new BorderPane(pane); borderPane.setBottom(hBox); // Create and register the handler btUp.setOnAction(new EventHandler() { @Override // Override the handle method public void handle(ActionEvent e) { text.setY(text.getY() > 10 ? text.getY() - 5 : 10); } });

btDown.setOnAction(new EventHandler() { @Override // Override the handle method public void handle(ActionEvent e) { text.setY(text.getY() < pane.getHeight() ? text.getY() + 5 : pane.getHeight()); } }); btLeft.setOnAction(new EventHandler() { @Override // Override the handle method public void handle(ActionEvent e) { text.setX(text.getX() > 0 ? text.getX() - 5 : 0); } }); btRight.setOnAction(new EventHandler() { @Override // Override the handle method public void handle(ActionEvent e) { text.setX(text.getX() < pane.getWidth() - 100? text.getX() + 5 : pane.getWidth() - 100); } });

// Create a scene and place it in the stage Scene scene = new Scene(borderPane, 400, 350); primaryStage.setTitle("AnonymousHandlerDemo"); // Set title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage } /** * The main method is only needed for the IDE with limited * JavaFX support. Not needed for running from the command line. */ public static void main(String[] args) { launch(args); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago