Question
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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started