Hey everyone. I have a problem. I can't find why my code won't convert Fehrenheit to Celsius. :sad:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CTemp extends JFrame
implements ActionListener {
private JButton button;
public static void main(String[] args) {
CTemp frame = new CTemp();
frame.setSize(400, 300);
frame.createGUI();
frame.setVisible(true);
}
private void createGUI() {
setDefaultCloseOperation(EXIT_ON_CLOSE);
Container window = getContentPane();
window.setLayout(new FlowLayout() );
button = new JButton("Fahrenheit converted to Celsius");
window.add(button);
button.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
int fahrenheit, celsius;
String fahrenheitString;
fahrenheitString = JOptionPane.showInputDialog("Tempature in Fahrenheit: ");
fahrenheit = Integer.parseInt(fahrenheitString);
celsius = (5 / 9) * (fahrenheit - 32);
JOptionPane.showMessageDialog(null, fahrenheit + " Degrees Fahrenheit\n" + "converted to\n" + celsius + " Degrees Celsius");
}
}