I am not able to access an instance variable of the outer class in the inner class. Its a simple swing app that i am creating using JRuby:
class MainApp
def initialize
...
@textArea = Swing::JTextArea.new
@button = Swing::JButton.new
@button.addActionListener(ButtonListener.new)
...
end
class ButtonListener
def actionPerformed(e)
puts @textArea.getText #cant do this
end
end
end
The only workaround i can think of is this:
...
@button.addActionListener(ButtonListener.new(@textArea))
...
class ButtonListener
def initialize(control)
@swingcontrol = control
end
end
and then use the @swingcontrol ins place of @textArea in the 'actionPerformed' method.