| Author |
Inner not knowing about outer
|
Al Wells
Ranch Hand
Joined: Apr 18, 2005
Posts: 87
|
|
I have, through the kind help of some of the people here, figured out some of my problems in learning swing. But, now, I am having trouble with getting an inner class to see objects in the outer class. What is wrong with my syntax that is causing this? Thanks in advance for your help.
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
|
It's because you've defined mainButton inside the constructor instead of defining it globally for the class. So it is only visible in the TestMainScreen constructor method.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
mainButton is a local variable declared in the constructor of the outer class. Local variables are only visible inside the method that declares them. If you want MainButtonListener to see it, make it into a member variable of the class -- i.e., declare it at class scope, and then assign it in the constructor as now.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
With that being said, several of your variables are going to have the same issue because they are in declared in the constructor. uNameField pWordField Will both need to be made global to the class.
|
 |
Al Wells
Ranch Hand
Joined: Apr 18, 2005
Posts: 87
|
|
Then this should do the trick? Thanks Greg and Ernest! [ May 23, 2005: Message edited by: Al Wells ]
|
 |
Gregg Bolinger
Ranch Hand
Joined: Jul 11, 2001
Posts: 15230
|
|
Originally posted by Al Wells: Then this should do the trick? Thanks Greg.
Yep, that should pretty much do it. Note also that your JOptionPane.showMessageDialog argumaents are missing the Dialog Title.
|
 |
Al Wells
Ranch Hand
Joined: Apr 18, 2005
Posts: 87
|
|
|
I noticed that when I just compiled. I am fixing now.
|
 |
 |
|
|
subject: Inner not knowing about outer
|
|
|