>"Bjorn Abelli" wrote...
>
[quoted text clipped - 8 lines]
>
>> Fifth, scratch all the redundant code in actionPerformed
"Alan Fried" wrote...
> Bjorn thank you so much for your help
> and I did as you said
Well, not *exactly* as I said, and you did some other changes as well... ;-)
You *still* create *local* variables for buttons and textfields instead of
using the instance variables...
And you didn't make them *instance* variables either, but *class* variables.
Ok, that would also work in this particular case, but try to think about the
difference between them, as you will need to know the difference in the
future.
Eliminate the local versions of textField, Celcius and Farenheit in all of
your methods. And by the way, make the instance of Temperature, therm, an
instance variable as well...
> but I get a compile error on:
>
> class BasicFrame extends Frame implements ActionListener{
>
> The serializable class BasicFrame does not declare
> a static final serialVersionUID field of type long.
I didn't get that error, so there is probably something special setting at
your machine...
But you're correct in saying that your code won't compile!
In *your* code the variable "therm" isn't reachable from within the method
actionPerformed, as it is a *local* variable inside the constructor. I
repeat, lift that as well *out* of the method, and make it an instance
variable (or a class variable with static if you must).
That you even can execute is because there are some old versions of the
classes around...
The cause of that error is simply because the textField you try to parse
*is* empty, which the error says in plain text.
> Exception in thread "AWT-EventQueue-0"
> java.lang.NumberFormatException: empty String
...and that is just because of what I told you in previous messages and as I
repeated above; don't duplicate the textfield and buttons as local
variables. What happens is that you're trying to parse the textfield that is
*local* inside the method, not the one on the form...
// Bjorn A
Alan Fried - 11 Dec 2004 16:27 GMT
>"Alan Fried" wrote...
>
[quoted text clipped - 5 lines]
>You *still* create *local* variables for buttons and textfields instead of
>using the instance variables...
Yes that was the problem it now runs correctly!
Thanx for your help