Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner not knowing about outer

 
Al Wells
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then this should do the trick?



Thanks Greg and Ernest!
[ May 23, 2005: Message edited by: Al Wells ]
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I noticed that when I just compiled. I am fixing now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic