I understand I will need to add actionlisteners, and use the .getText() method, but how do I put that into the variable answer.
Tony Docherty wrote:The problem is OtherField is local to the color() method. It needs to be an instance variable.
BTW please use variable names that conform to the Java naming conventions ie otherField and not OtherField
How do I make it an instance variable?
I don't want to change the code to much if possible.
Tony Docherty wrote:
How do I make it an instance variable?
Instance variables are also known as member variables and/or fields if that helps you, if not read this http://docs.oracle.com/javase/tutorial/java/javaOO/variables.html
I don't want to change the code to much if possible.
I am a little confused that you have code that doesn't work and you are concerned about not having to change it too much to get it working.
Tony Docherty wrote:Do you understand what the scope of a variable is or what the difference between a local and instance variable is?
Tony Docherty wrote:
The problem in your code is that the variable OtherField is declared in the color() method and so is only visible in the color() method. Hence it can't be referenced in the ActionListener.
Tony Docherty wrote:What error does it give you and what does your code look like?
luck, db
There are no new questions, but there may be new answers.
You have to be odd to be #1 - Seuss. An odd little ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|