|
From: D-Man <ds...@ri...> - 2001-04-03 18:19:04
|
The change you need to make is shown below.
In Java, C++ and Eiffel, member functions can be called on the current
object without specifying the object. In Python, however, the object
(usually named 'self' but called 'this' in Java and C++, 'current' in
Eiffel) must be explicitly named.
The following 2 runme functions in java code are equivalent, and serve the
same purpose as the python function following it.
public class Foo
{
public void func( )
{
System.out.println( "func was called" ) ;
}
public void runme( )
{
func() ;
}
public void runme2( )
{
this.func() ;
}
}
class Foo :
def func( self ) :
print "func was called"
def runme( self ) :
func() # this won't work as you've seen in your code
def runme2( self ) :
self.func() # this will work as expected
Conclusion :
As you read through sample Java code, prepend "this" (for java) or
"self" (for python) to each method call on the current object.
IMO explicit is better than implicit so I use 'this' in all my
Java code where it won't be illegal (ie nested event handler
classes)
HTH,
-D
On Wed, Apr 04, 2001 at 02:14:38AM -0400, cindy wrote:
| Here is the code for SketchFrame.
|
| from javax import swing
| import java
| import java.awt.event
|
| class SketchFrame(swing.JFrame):
| def __init__(self, title):
| // some code left out - it build a menu bar
| enableEvents(java.awt.event.WindowEvent.WINDOW_EVENT_MASK)
self.enableEvents(java.awt.event.WindowEvent.WINDOW_EVENT_MASK)
^^^^^
|
| def processWindowEvent(self, event):
| if (event.getID() == java.awt.event.WindowEvent.WINDOW.CLOSE):
| java.awt.event.dispose() # not sure if this works
| yet. I haven't gotten to this point.
| java.awt.System.exit(0)
| swing.JFrame.super.processWindowEvent(event)
|
|