Program Plan:
- Include the required import statement.
- Define the main class.
- Declare the necessary variables
- Using start initialize the required.
- Create the border pane, radio button, text field, toggle group and button.
- Set everything into the panel.
- Add the actions event to the button.
- Create a scene and place the pane in the stage.
- Set the title.
- Place the scene in the stage.
- Display the stage.
- Define the main method using public static main.
- Initialize the call.
The below program will display the statement in different colors and move the statement left and right using GUI as follows:
Explanation of Solution
Program:
//import statement
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.RadioButton;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
//definition of "Test" class
public class Test extends Application
{
//declare the required variables
private double pane_width = 500;
private double pane_height = 150;
@Override
/*start method gets overridden in the application class*/
public void start(Stage pri_stage)
{
//create a text
Text t = new Text(20, 40, "
//set the font
t.setFont(new Font("Times", 20));
//create a text
Pane p = new Pane();
//create a label
p.getChildren().add(t);
//set the style
p.setStyle("-fx-border-color: gray");
//create a radio buttons
RadioButton r_red = new RadioButton("Red");
RadioButton r_yellow = new RadioButton("Yellow");
RadioButton r_black = new RadioButton("Black");
RadioButton r_orange = new RadioButton("Orange");
RadioButton r_green = new RadioButton("Green");
//create a toggle group
ToggleGroup group = new ToggleGroup();
//set the toggle groups
r_red.setToggleGroup(group);
r_yellow.setToggleGroup(group);
r_black.setToggleGroup(group);
r_black.setSelected(true);
r_orange.setToggleGroup(group);
r_green.setToggleGroup(group);
//create a box
HBox h_box = new HBox(5);
//create a label
h_box.getChildren().addAll(r_red, r_yellow, r_black, r_orange, r_green);
//set the alignment
h_box.setAlignment(Pos.CENTER);
//create a button
Button bt_left = new Button("<=");
Button bt_right = new Button("=>");
//create a box for button
HBox h_boxForButtons = new HBox(5);
//create a label
h_boxForButtons.getChildren().addAll(bt_left, bt_right);
//set the alignment
h_boxForButtons.setAlignment(Pos.CENTER);
//create a border pane
BorderPane border_pane = new BorderPane();
//set the border pane
border_pane.setTop(h_box);
border_pane.setCenter(p);
border_pane.setBottom(h_boxForButtons);
// create a scene and place it in the stage
Scene scene = new Scene(border_pane, pane_width, pane_height + 40);
//set the stage title
pri_stage.setTitle("Exercise16_01");
//place the scene in the stage
pri_stage.setScene(scene);
//display the stage
pri_stage.show();
// action event for the buttons gets created
r_red.setOnAction(e->t.setStroke(Color.RED));
r_yellow.setOnAction(e->t.setStroke(Color.YELLOW));
r_black.setOnAction(e->t.setStroke(Color.BLACK));
r_orange.setOnAction(e->t.setStroke(Color.ORANGE));
r_green.setOnAction(e->t.setStroke(Color.GREEN));
bt_left.setOnAction(e->t.setX(t.getX() - 1));
bt_right.setOnAction(e->t.setX(t.getX() + 1));
}
//definition of main method
public static void main(String[] args)
{
//initilaize calls
launch(args);
}
}
Want to see more full solutions like this?
Chapter 16 Solutions
Instructor Solutions Manual For Introduction To Java Programming And Data Structures, Comprehensive Version, 11th Edition
- Computer Science JAVA (NOT KOTLIN) This must be done inside of Fragment with tab layout. The design of the tab: a. any image b. Add two thumbnails at top corners of the image above c. Allow the user to draw on screen, allow the user to select the pen thickness and color (give 3 options each), with a button to update the pen properties. d. Button to clear the drawing.arrow_forwardModify the Dice Poker program from this chapter to include any or all of the following features: 1- Splash Screen. When the program first fires up, have it print a short introductory message about the program and buttons for "Let's Play" and "Exit." The main interface shouldn't appear unless the user se- lects "Let's Play." 2-Add a "Help" button that pops up another window displaying the rules of the game (the payoffs table is the most important part). 3-Add a high score feature. The program should keep track of the 10 best scores. When a user quits with a good enough score, he/she is invited to type in a name for the list. The list should be printed in the splash screen when the program first runs. The high-scores list will have to be stored in a file so that it persists between program invocations.arrow_forward(UI Elements) Describe 5 ways in which the user interfaces of any of the 3 major operating systems (Windows, iOS, Android) differ. You can consider things like layout, navigation, colour, light, materials, shapes, specific control elements etc. You may use diagrams to illustrate your points as well as text.arrow_forward
- Exercise#2: Calculate the area and perimeter of right angled triangle.arrow_forwardTRY to do asap Urgently neededarrow_forwardCan someone write this code? Write your own MineSweeper game, using wxWidgets and C++. This game should consist of a 10 x 10 grid of buttons. When the game starts the buttons should all appear to be plain, until the user clicks the first button. Once the user clicks that first button, the game should load in the hidden mines. Then the first button the user clicked on should display the number that tells the user how many mines surround the first box in the grid that (s)he chose. The user should be able to play the game just like the normal MineSweeper game until either (s)he lands on a mine and the game ends, os until (s)he wins the game by revealing all the squares that do not contain mines. Make sure to use a 24 point font so the numbers are nicely visible. To submit your answer, please paste in all your Source Code into a Word document. Also paste in at least two screen shots from the game; one from the beginning of the game and another showing the message that is displayed when…arrow_forward
- / Please do JAVA (2nd time posting the previous answers didn't help much ) Q. Compile and run the ImageGen01 application. Experiment with alternate formulas for the value of c. Add two more int variables so that you can separately set the RGB values of color and experiment some more. Share your most interesting results with your classmates //please post a easy to understand solution.arrow_forwardLab #8 – Crazy Pet Store Background: The local pet store has 35 different bowls with fish in them arranged in a circle in the "fish room." The first six have goldfish, the next seven have guppies, the next nine have angel fish, the next eight have goldfish, and the last five hold tiger fish. As the bowls vary in size, the number of fish that are in each bowl at the start of the day also varies. The count of fish in each bowl is as follows: Bowls 1- 3: Bowls 4 – 7: 15 fish 8 fish 19 fish 16 fish Bowl 8: Bowls 9 – 12: Bowls 13 – 22: 14 fish Bowls 23 – 24: 31 fish 9 fish 26 fish Bowls 25 – 29: Bowls 30 – 33: Bowls 34 – 35: 8 fish Houston...We have a Problem: A trained seal finds its way into the store. The seal begins to eat fish in the following manner. a. It walks over to bowl #1. b. It counts four bowls and then eats a fish (the first fish it eats comes from bowl #4 and it's a goldfish). c. It comes from bowl #8 and it's a guppy. counts four, starting with the next available bowl, and…arrow_forwardPython Modify the Dice Poker program from this chapter to include any or all of the following features: 1- Splash Screen. When the program first fires up, have it print a short introductory message about the program and buttons for "Let's Play" and "Exit." The main interface shouldn't appear unless the user se- lects "Let's Play." 2-Add a "Help" button that pops up another window displaying the rules of the game (the payoffs table is the most important part). 3-Add a high score feature. The program should keep track of the 10 best scores. When a user quits with a good enough score, he/she is invited to type in a name for the list. The list should be printed in the splash screen when the program first runs. The high-scores list will have to be stored in a file so that it persists between program invocations.arrow_forward
- Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each part has one correct answer. Thank you. Part 1 - Which sets the frame (or a "form") width to 100 pixels and the height to 200 pixels? A. setSize(100, 200);B. setSize(200, 100);C. setDims(100, 200);D. setDimensions(200, 100);E. setWidth(100); setHeight(100); Part 2 - In Java, which can ensure the "Form" class to inherit from JFrame class? A. public class Form gets JFrame { }B. public class Form inherits JFrame { }C. public class Form extends JFrame { }D. public class Form : public JFrame { }E. public class Form implements JFrame { }arrow_forward(THIS IS FOR CENGAGE MINDTAP. HIGHLY RECOMMEND USING THIS. IF ISSUE OCCUR, USE DEVC++ 5.11) Instructions Jason opened a coffee shop at the beach and sells coffee in three sizes:small (9 oz),medium (12 oz),and large (15 oz). The cost of one small cup is $1.75, one medium cup is $1.90, and one large cup is $2.00. Write a menu-driven program that will make the coffee shop operational. Your program should allow the user to do the following: Buy coffee in any size and in any number of cups. At any time show the total number of cups of each size sold. At any time show the total amount of coffee sold. At any time show the total money made. Your program should consist of at least the following functions: a function to show the user how to use the program; a function to sell coffee; a function to show the number of cups of each size sold; a function to show the total amount of coffee sold; and a function to show the total money made. Your program should not use any global variables and…arrow_forward3. Write a GUI application with a single button. Initially the button is labelled "0". When it is first clicked the label becomes "1". When it is clicked a second time it becomes "2", and each time it is clicked it cycles between "0", "1" and "2".arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education