I have the following GUI code but my JLabel for results doesn't work when either of the buttons are pushed
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TempConverterPanel extends JPanel
{
private JLabel input, results;
private JButton output_f, output_c;
private JTextField temp, fahrenheit, celsius;
public TempConverterPanel()
{
setLayout (new GridLayout (3, 1));
setLayout (new FlowLayout ());
setPreferredSize (new Dimension(400, 175));
setBackground (Color.red);
//asks for the temp input in fahrenheit
input = new JLabel ("Enter the temperature you want to convert:");
output_f = new JButton ("Convert to Celsius: ");
output_c = new JButton ("Convert to Fahrenheit: ");
results = new JLabel ("Input converted to is: ");
temp = new JTextField (6);
output_f.addActionListener (new FahrenheitListener());
output_c.addActionListener (new CelsiusListener());
add (input);
add (temp);
add (output_f);
add (output_c);
add (results);
}
//sets the listener for the fahrenheit temp
private class FahrenheitListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
double fahrenheitTemp, celsiusTemp;
String text = temp.getText();
fahrenheitTemp = Double.parseDouble(text);
celsiusTemp = (fahrenheitTemp - 32) * 5/9;
results.setText (Double.toString (celsiusTemp));
}
}
//sets the listener for the celsius temp
private class CelsiusListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
double celsiusTemp, fahrenheitTemp;
String text = temp.getText();
celsiusTemp = Double.parseDouble (text);
fahrenheitTemp = celsiusTemp * 9/5 + 32;
results.setText (Double.toString (fahrenheitTemp));
}
}
}
is there anyway i can fix this problem