Question
JavaFx Overview The purpose of this exercise is to practice writing Java GUI applications. Like most software, you will build this in stages starting with
JavaFx
Overview
The purpose of this exercise is to practice writing Java GUI applications. Like most software, you will build this in stages starting with design then testing each stage before proceeding to the next.
This lab will provide a description of the application requirements. Some of the programming requires you to apply your learning of the concepts in different ways than presented. You may need to review the class slides or JavaDocs to complete this lab. Some suggestions will be provided. If you really get stuck, ask the instructor or TA, we may suggest a direction.
Part 1: Start simple labels and entry fields (2 Points)
Before creating the GUI shown below, answer these questions:
What layout (Pane) will you use?
Create a GUI class called Orders that contains right aligned labels for text fields as shown. Label the object names in the code with the text labels. Place all of the components in an appropriate Pane, then add the Pane to the Scene. This is a common practice, easily allowing moving of the Pane to another Scene, should it be needed.
Write the full statement used to place the Pane.
HINT: If you use a GridPane, call GridPane.setHalignment(lblXX, HPos.RIGHT) for each of your labels then they will be right aligned when in a GridPane.
Part 2: Control Buttons (3 Points)
Add buttons to control the actions that will take place on the screen. Your screen should now look similar to this diagram.
The easy way to do this is to change the root Pane to a VBox. Create the GridPane from before, but call it something different from root (e.g., gpTop).
Also create a FlowPane (example fpBot) and place the buttons in it: fpBot.getChildren().addAll(btn1, btn2 );
Then add the GridPane and the FlowPane to the VBox: root.getChildren().addAll(gpTop, fpBot);
Change the Amount owed field to not allow input. Hint: Within Javadocs under TextField, search for the inherited setEnabled method.
Name all layout managers used:
In what area are the buttons placed?
In what class is setEnabled defined?
Part 3: Buttons control (5 Points)
Adding controls for the buttons should start with the easier ones first.
Exit: Exit the program
Clear: Clears the text fields. Can setText() to null or (blank).
Calculate: Multiply the Number of by the cost per item, place result in the Amount owed field. Format the amount owed result to have two decimal places. Hint: See Strings format method.
Save: Open/append to a text file named 121Lab1.csv. Write in comma-separated format, the items name within quotes, the number of items, cost per item and the calculated amount owned. Each time the user clicks Save, first execute the
Calculate code. The calculation code should only appear once in your program.
Check the javadocs for constructors for FileOutputStream to see how to open a file for appending.Gi
//121Lab1.csv
Toaster 10 15.95 159.5 Blender 1 25.5 25.5 Electric Fryer 2 13.65 27.3 Mixer 5 11.95 59.75 Food Processor 2 19.9 39.8 Rolling Pin 2 3.45 6.9
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