0

I have a class lets say myFrame that extends JFrame. On this frame I have a button with a action listener event. When this event triggers I want to make changes to the class(myFrame) like I would have done in the constructor of the class using this.add() or whatever function I need.

The problem is that if I use "this" in this action listener I am no longer referring to the current instance of the class myFrame. I vaguely remember that I have come across this issue before but I cannot remember how I went around it. I think I might have assigned this to some variable in the constructor of the class.

Ian
  • 151
  • 1
  • 3
  • 9
  • Use `myFrame.this.someMethod();` -- append the name of the class before the `this`. – Hovercraft Full Of Eels Sep 03 '16 at 15:53
  • As an aside, you will want to learn and use [Java naming conventions](http://en.wikipedia.org/wiki/Naming_convention_(programming)#Java). Variable names should all begin with a lower letter while class names with an upper case letter. Learning this and following this will allow us to better understand your code, and would allow you to better understand the code of others. – Hovercraft Full Of Eels Sep 03 '16 at 15:53

0 Answers0