inner classes

Fredrik Lundh fredrik at pythonware.com
Tue Apr 30 17:38:06 EDT 2002


"Hermann Hesse" wrote:

> Can someone give an example of how you'd use bound methods to replace inner
> classes in python?

quoting from some random Java tutorial:

public class SomeGUI extends JFrame
{
   // inner class definitions
   class Button1Handler implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
   {
         // do something
      }
   }

   protected void buildGUI()
   {
      button1 = new JButton();
      button1.addActionListener(new Button1Handler());

here's the python version:

class SomeGUI(PyFrame):

    def Button1Handler(self, e):
        # do something

    def buildGUI(self):
        button1 = PyButton()
        button1.addActionListener(self.Button1Handler)

where "self.Button1Handler" evaluates to a callable object that
represents the Button1Handler method for a specific SomeGUI
instance.

</F>





More information about the Python-list mailing list