-
I have a problem with a piece of code. Basically, I can get the value for the text field everytime I click Submit button but I can't do the calculation and set the label to the new value. Here is the code that deals with it. I have the actionPerformed method followed by the method that does the calculation and displays the new value:
public void actionPerformed (ActionEvent e) {
if (e.getSource()==Submit) {
String s=FahrenheitTextField.getText();
try {
Fahrenheit = new DecimalFormat().parse(s.trim()).doubleValue();
}
catch(Exception exp) {
System.out.println("problem converting");
}
displayCelsius();
}
if (e.getSource()==Reset) {
//code to clear the textfield
}
}
public void displayCelsius() {
System.out.println(Fahrenheit);
x=((Fahrenheit-32)*(5/9));
Celsius = (int)x;
System.out.println(x);
CelsiusConvertionLabel.setText(""+Celsius);
}
Thanks for the help
-
isolated the problem
actually this piece of code is giving me the problem:
x=((Fahrenheit-32)*(5/9));
Celsius = (int)x;
Thanks