Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Inner Class


  • Please log in to reply
16 replies to this topic

#13 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 12 November 2011 - 02:46 PM

I'm so sorry but this not make sense to me. Figured out that if I can find a way to cast the e.getSourse I will achieve what I want, mean something like
JButton button = (JButton)e.getSourse();

I have this but can't use getters and setters methods that I created in CoordButton method. Also, if I change the line with...
CoordButton button = (CoordButton)e.getSourse();

underline both CoordButton with error "CoordButton can't resolve to a type"..Any idea?
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#14 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 12 November 2011 - 03:11 PM

class GUIClass {

     JButtons buttons...

     OtherClass oc = new OtherClass( this );

     // create getters for the buttons

     ...

}



class OtherClass implements ActionListener { 

    GUIClass theGUICLass;

    public OtherClass( GUIClass theGUiClass ) {

       this.theGUIClass = theGUIClass;

    }

    actionPerformed() { ...

           src = getSource ...

           use theGUIClass object to gain reference to buttons in your GUIClass

    }

}


  • 0

#15 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 12 November 2011 - 04:46 PM

The problem is that getters for the buttons are in inner class, that's why OtherClass does not recognised it
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#16 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 12 November 2011 - 05:00 PM

Then create a getter to get the object of the inner class? I'm not sure I understand. Perhaps the design of your mvc needs some rethinking.
  • 0

#17 toto_7

toto_7

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 244 posts

Posted 12 November 2011 - 05:01 PM

Hmm...I will try to rethink my structure
  • 0

"Programming is like **. One mistake and you have to support it for the rest of your life."

-Michael Sinz




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download