title: Event handling with Jython & Swing
body: <p>I'm making a GUI by using Swing from Jython. Event handling seems to be particularly elegant from Jython, just set</p>
  
  <pre><code>JButton("Push me", actionPerformed = nameOfFunctionToCall)
  </code></pre>
  
  <p>However, trying same thing inside a class gets difficult. Naively trying</p>
  
  <pre><code>JButton("Push me", actionPerformed = nameOfMethodToCall)
  </code></pre>
  
  <p>or</p>
  
  <pre><code>JButton("Push me", actionPerformed = nameOfMethodToCall(self))
  </code></pre>
  
  <p>from a GUI-construction method of the class doesn't work, because the first argument of a method to be called should be <em>self</em>, in order to access the data members of the class, and on the other hand, it's not possible to pass any arguments to the event handler through AWT event queue. The only option seems to be using lambda (as advised at <a href="http://www.javalobby.org/articles/jython/" rel="nofollow noreferrer">http://www.javalobby.org/articles/jython/</a>) which results in something like this:</p>
  
  <pre><code>JButton("Push me", actionPerformed = lambda evt : ClassName.nameOfMethodToCall(self))
  </code></pre>
  
  <p>It works, but the elegance is gone. All this just because the method being called needs a <em>self</em> reference from somewhere. Is there any other way around this?</p>