Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Be creative and modify any of the programs in Chapter 13. For example, you could choose the ColorChooser Application and make the following modifications:Change

Java

Be creative and modify any of the programs in Chapter 13. For example, you could choose the ColorChooser Application and make the following modifications:Change the colors in the color palette and/orChange the layout,

or shape Or, you could choose the CoverViewer application and make it into a TourGuide or a LearningGuide application with the following modificationsTourGuide: Countries with pictures LearningGuide:Objects with images

Or, any other application of your choice.This is your chance to create an application to fit your need. Make sure you use something that is close to the templates given in the book for simplicity and reference.

Program to modify:

// ColorChooser.java // Main application class that loads and displays the ColorChooser's GUI. import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class ColorChooser extends Application { @Override public void start(Stage stage) throws Exception { Parent root = FXMLLoader.load(getClass().getResource("ColorChooser.fxml")); Scene scene = new Scene(root); stage.setTitle("Color Chooser"); stage.setScene(scene); stage.show(); }

public static void main(String[] args) { launch(args); } } ColorChooserController.java // Controller for the ColorChooser app import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.scene.control.Slider; import javafx.scene.control.TextField; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle;

public class ColorChooserController { // instance variables for interacting with GUI components @FXML private Slider redSlider; @FXML private Slider greenSlider; @FXML private Slider blueSlider; @FXML private Slider alphaSlider; @FXML private TextField redTextField; @FXML private TextField greenTextField; @FXML private TextField blueTextField; @FXML private TextField alphaTextField; @FXML private Rectangle colorRectangle;

// instance variables for managing private int red = 0; private int green = 0; private int blue = 0; private double alpha = 1.0;

public void initialize() { // bind TextField values to corresponding Slider values redTextField.textProperty().bind( redSlider.valueProperty().asString("%.0f")); greenTextField.textProperty().bind( greenSlider.valueProperty().asString("%.0f")); blueTextField.textProperty().bind( blueSlider.valueProperty().asString("%.0f")); alphaTextField.textProperty().bind( alphaSlider.valueProperty().asString("%.2f"));

// listeners that set Rectangle's fill based on Slider changes redSlider.valueProperty().addListener( new ChangeListener() { @Override public void changed(ObservableValue ov, Number oldValue, Number newValue) { red = newValue.intValue(); colorRectangle.setFill(Color.rgb(red, green, blue, alpha)); } } ); greenSlider.valueProperty().addListener( new ChangeListener() { @Override public void changed(ObservableValue ov, Number oldValue, Number new Value) { green = newValue.intValue(); colorRectangle.setFill(Color.rgb(red, green, blue, alpha)); } } ); blueSlider.valueProperty().addListener( new ChangeListener() { @Override public void changed(ObservableValue ov, Number oldValue, Number newValue) { blue = newValue.intValue(); colorRectangle.setFill(Color.rgb(red, green, blue, alpha)); } } ); alphaSlider.valueProperty().addListener( new ChangeListener() { @Override public void changed(ObservableValue ov, Number oldValue, Number newValue) { alpha = newValue.doubleValue(); colorRectangle.setFill(Color.rgb(red, green, blue, alpha)); } } ); } }

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago