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
Introduction to Java Programming and Data Structures Comprehensive Version (11th Edition)
- ) Use TKinter or cslgraphics.py to build a graphical user interface to calculate the area of a rectangle. The window should have entries for Length and Width, two buttons, Calculate and Quit, and labels displaying the calculated Area.arrow_forwardR Language: 1) Select the correct methods used to create a scatter plot in R?A. scatterplot3d()B. scatterplot()C. qplot()D. plot()E. All options above are correct 2) What is the use of the addTiles() method in R?A. To divide the map into tiles.B. To zoom in on the map to see the different countries and streets in detail.C. To create a tiled view of the map.D. All options above are correct. 3) which method is used to publish a tile layer to the map.A. leaf()B. leaflet()C. addTiles()D. None of the options are correctarrow_forward(2) You will need to use the module graphics.py for this program. Write a program that con- structs a window, invites the user to present two clicks for the opposite vertices of a rectangle and then draws a red rectangle with those two opposite vertices. Finally, prompt the user to click to close the window.arrow_forward
- Modify the Dice Poker program from this chapter to include any or all ofthe following features:a) Splash Screen. When the program first fires up, have it print a shortintroductory message about the program and buttons for "Let's Play''and "Exit." The main interface shouldn't appear unless the user selects "Let's Play."b) Add a "Help" button that pops up another window displaying therules of the game (the payoffs table is the most important part).c) Add a high score feature. The program should keep track of the 10best scores. When a user quits with a good enough score, he/she isinvited to type in a name for the list. The list should be printed inthe splash screen when the program first runs. The high-scores listwill have to be stored in a file so that it persists between programinvocations.arrow_forwardComputer 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_forwardFor this lab, you will be doing the following in C#: 1) Create a Home form with buttons that when clicked, will open the Account, Email, and eventually the Contact forms. The Account form should be opened in "View" mode. 2) Add code to the Login form so the Account form opens when the user clicks "Create New Account". The Account form should be opened in "Modify" mode. 3) Add code to the Login form that validates the user input before allowing the user the access the Home form. For now, just verify the user enters "user1" and "12345" for the username and password respectively.arrow_forward
- 1. Code-Tracing - Without running / testing the following code, predict what the following program would print on the screen if you printed freeze and then boil. Write your answer in the comment section when submitting your work. For help with code-tracing see the code tracing page in this module. ments freeze - int(32) boil - int(212) freeze - 0 boil - 100 print(freeze, boil) # what would this print to the monitor? Research • Submit your answer in the comment section.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_forward4.) Directions: Multiple Choice - For each Multiple Choice Question Part, select the correct letter choice. There can only be one letter choice answer for each Multiple Choice Question Part. For the True or False Sentence Questions, explain why, provide reasons why, they are True or False Sentences. PART 1 - True or False: Assembling an application from available resources is not a good idea. A.) True B.) False PART 2 - With only red light on an object covered with blue material, the object appears: A.) red B.) blue C.) black D.) violet PART 3 - True or False: Smart phones should have a different user interface than a tablet for some apps. A.) True B.) False PART 4 - True or False: You generally cannot do Graphical User Interface GUI programming on your computer as it comes from the factory and special setup is usually required. A.) True B.) False PART 5 - True or False: A mouse press creates an event. The event is automatically handled by a Graphical User Interface GUI program.…arrow_forward
- Using Java Task 1) Write a class, named Counter, that prints numbers 0 to 9 on a single line and skips to the next line. Task 2) Repeat that an indefinite number of times until the user sets a flag done as 'false'. Task 3) Run the Counter repeatedly until the user wants to set the flag as 'false'. Task 4) Develop a simple GUI with a STOP button that will stop the Counter class from printing the numbers indefinitely. In other words, you will automatically start the Counter class, and the STOP button will stop its execution. Task 5) Add a START button to your GUI that will start the Counter. STOP button will still pause the counter. You should be able to start the Counter again by pressing the START button. Task 6) Write a similar class Counter2 that will print numbers in the reverse order, 9 to 0, and skip to the next line. Run both counters on different threads, START and STOP buttons should control both of the counters together. Run your application, and observe how responsive are the…arrow_forwardVisual basicarrow_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_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