CISS-110 Project 8b
Write a Java program to create a GUI using JavaFX
with GridPane
, TextField
, Label
, RadioButton
, ToggleGroup
and Button
objects. This is continuation of Project 7 which used the text-based menu driven model.
Learning outcomes
- Implementing user-defined methods.
- Working with JavaFX.
- Working with events.
- Confirmation program produces desired results.
Write two value-returning methods called farToCel()
and celToFar()
. These two methods will convert temperatures from Fahrenheit to Celsius and Celsius to Fahrenheit respectively. They will each take a single int
parameter and return the converted value as an int
. (These should already be done and can be taken from Project 7. No other code from Project 7 will be of any consequence.)
Here is a picture of what you will create:
In your start()
method, do the following:
- Create two labels “Temperature:” and “Results:” that are centered.
- Create two text fields with:
- A maximum width of 200 for each.
- The temperature text field should be initially set to zero.
- The results text field has no initial value and should not be an editable field.
- Create two radio buttons “Celsius to Fahrenheit” and “Fahrenheit to Celsius”.
- Set the window title to “Celsius and Fahrenheit Conversion”
- Set the layout to the GridPane layout. Make the hgap and vgap values 10.
- Add the temperature label and text field.
- Add the radio buttons.
- Add the result label and text field.
- Add the button as span.
- Assign the button handler using the Lambda Expression method.
- Set the window size to 500 pixels wide by 200 pixels high.
For the button handler you should perform the following:
- Determine which radio button has been selected.
- Read the temperature text field value.
- Convert the String temperature to an integer.
- Convert the temperature from one scale to the other.
- Display the relative information in the results text field.
For 5 points of extra credit, read the try/catch
section of Chapter 12 and do not allow non-numeric quantities for Temperature text field and display an error in the Result text field like so:
You must include this in the final program when submitted.
Submit the project to the Learning Management System as Project8_lastname.java.