Can anyone tell me why I'm getting a NumberFormatException, coz for the life of me I can't see whats wrong with it. It's basically an applet that allows you to enter 2 numbers which when you click on 1 of 4 radio buttons( +, -, *, / ) and then click calculate, displays the answer in a JTextField. I've used the method getText() to retrieve the inputted strings, then converted these to ints, did the calculation, then converted them back to a String in order to display in the result JTextField.(Is it possible to leave the result as an int to display in result field?)
It seems you are parsing the textfields for the val1 and val2 in the init(). But at initialising time you will not have anything in there. This has to be done once you have typed in some number in there and clicked the calculate button. So include the val1,val2 assigning statements inside your action performed method and then it should work Regards
Joined: Jan 23, 2002
Abhilash, Iv'e done as you said and moved the assignments to here:
So, I now get the GUI displaying propery. I can enter 2 numbers into the textfields and click on a radio button such as'+' to add the 2 numbers together. I then click the 'calculate' button but nothing appears in the result textfield. Is there something wrong in the if statements to do with setText()???