Question: Write a Java program to create a GUI using JFrame, JTextField, JLabel and JButton objects. This is continuation of Project 7 which used the text-based
Write a Java program to create a GUI using JFrame, JTextField, JLabel and JButton objects. This is continuation of Project 7 which used the text-based menu driven model.
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 window constructor, do the following:
Create two labels Temperature: and Results: (text centered).
Create two text fields:
The temperature text field is 10 columns wide and should be initially set to zero.
The results text field is 40 columns wide, has no initial value and should not be an editable field.
Create two buttons Celsius to Fahrenhiet and Fahrenheit to Celsius.
Set the window title to Celsius and Fahrenheit Conversion
Create the Container for the content pane:
Set the layout to the Grid layout of 3 rows by 2 columns.
Add the temperature label and text field.
Add the buttons.
Add the result label and text field.
Assign the button handlers (discussed below).
Set the window size to 375 pixels wide by 120 pixels high.
Set the default close operation to EXIT_ON_CLOSE and set the window visible.
For the button handlers, recall that you will need to create additional classes that implement the ActionListener interface. For each actionPerformed() method, you should:
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.
The main() method should have only one line of code:
| p8 window = new p8(); |
Which creates a new p8 object and assigns it to the reference variable window.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
