Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have written most of my program, but have encountered a few snags in the proce

ID: 3642139 • Letter: I

Question

I have written most of my program, but have encountered a few snags in the process. Can you please write the following program so I may successfully master this small project, thank you!


Write a GUI (Graphical User Interface) in Java to do the following: The GUI should convert Centigrade to Fahrenheit. It should have a JLabel to say Enter Centigrade and a JTextField in front of it for the user to enter a number. In the next line have another JLabel to say Fahrenheit and JTextField to show the result of the conversion. You must have a JTextArea which shows the history of all conversions. Also have a JButton that when you push does the conversion. A rough example of what is desired is pictured below.

Explanation / Answer

please rate import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; /** * The Class Temperature. */ public class Temperature extends JFrame implements ActionListener{ /** The Constant serialVersionUID for version of program. */ private static final long serialVersionUID = 1L; /** The Constant FRAME_HEIGHT. */ static final int FRAME_HEIGHT = 200; /** The Constant FRAME_WIDTH. */ static final int FRAME_WIDTH = 300; /** The history is stored in this variable. */ String history = new String(); /** The label l1 to display information. */ JLabel l1 = new JLabel("Enter centigrade "); /** The label l2 to display information. */ JLabel l2 = new JLabel("Temperature in farenhiet "); /** The submit button to perform require action. */ JButton submit = new JButton("Convert"); /** The stored history is displayed with this text area. In case the area is too large maximize the screen. */ JTextArea storedHistory = new JTextArea(10,25); /** The celcius input field. */ JTextField celcius = new JTextField(5); /** The farenheit output field. */ JTextField farenheit = new JTextField(5); /** * Converts temperature from celcuius to farenheit. * * @param celcius the celcius * @return the double */ double convertTemperature(double celcius){ double farenheit = 0.0; farenheit = celcius * 9 / 5 + 32.0 ; return farenheit; } /** * Instantiates a new temperature. */ Temperature(){ super("Temperature conversion"); setLayout(new FlowLayout()); add(l1); add(celcius); add(l2); add(farenheit); add(submit); add(storedHistory); farenheit.setEditable(false); setVisible(true); submit.addActionListener(this); this.setSize(FRAME_WIDTH, FRAME_HEIGHT); } /** * The main method. * * @param args the arguments */ public static void main(String[] args){ new Temperature(); } @Override public void actionPerformed(ActionEvent ae) { /* * on clicking submit button the required actions are performed */ if(ae.getActionCommand().equals("Convert")){ double celcius = Double.parseDouble(this.celcius.getText()); double farenheit = convertTemperature(celcius); this.farenheit.setText(farenheit+""); history = celcius+" in Centigrade is "+farenheit+"in Farenhiet. "+history; storedHistory.setText(history); } } }