Results 1 to 2 of 2

Thread: doing a calculation through method calling

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    69

    Smile

    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

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Posts
    69

    isolated the problem

    actually this piece of code is giving me the problem:

    x=((Fahrenheit-32)*(5/9));
    Celsius = (int)x;


    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width