|
From: cindy <inf...@pi...> - 2001-04-03 17:10:58
|
The code is not exactly the same as the book.
In Sketcher.py I have-
import java
from SketchFrame import *
class Sketcher:
def __init__(self):
true = 1
title = 'sketcher'
self.aSketchFrame = SketchFrame(title)
self.theKit = self.aSkechFrame.getToolkit()
self.wndSize = setBounds(self.wndSize.width/4,
self.wndSize.height/4,
self.wndSize.width/2,
self.wndSize.height/2)
self.aSketchFrame.setVisible(true)
if __name__ == '__maine__'
aSketcher = Sketcher()
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)
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)
> On Tue, Apr 03, 2001 at 10:21:29PM -0400, cindy wrote:
> | Hi again,
> | If I may reiterate what you said to help me understand.If module Foo.py
> | has the statement "enableEvents(AWTEvent.WINDOW_EVENT_MASK)" and
> | module Bar.py does a composite on module Foo.py, then I have to pass
> | the instance name to module Foo.py to qualify the method enableEvents()
> | thus
> | "instanceName.enableEvents(). If this is so how do I pass the instance
> | name
> | in the creation of the instance? If I have the statement in Bar.py
> | "self.myInstance = Foo().
> | Thanks.
> | Wayne
>
> I'm not sure if I completely understand your goals and your design.
> Also, I think you mixed up modules and classes in your description
> above.
>
> I just read the docs for java.awt.Component.enableEvents( long ) and
> noticed the following :
>
> This method only needs to be invoked by subclasses of
> Component which desire to have the specified event types
> delivered to processEvent regardless of whether or not a
> listener is registered.
>
> Are you trying to create a subclass of Component that needs to receive
> events even if no listeners are registered? Could you post some code
> showing what it is you are currently trying to do?
>
> If you have a class Foo that inherits from component, you could do
> something like the following, but I'm not sure if it is what you are
> looking for.
>
> ---- in some .py file ------
> import java
>
> class Foo( java.awt.Component ) :
> def __init__( self ) :
> # note that 'self' now refers the the instance of 'Foo' and
> # therefore is-a instance of 'Component'
> self.enableEvents( java.awt.AWTEvent.WINDOW_EVENT_MASK )
>
> def processEvent( self , event ) :
> """
> @sig protected void processEvent( java.awt.AWTEvent event )
>
> this method must be defined or you will end up with errors
> when the event dispatcher tries to call it
> """
>
> print "Found an event!"
> print event
>
> HTH,
> -D
>
> _______________________________________________
> Jython-users mailing list
> Jyt...@li...
> http://lists.sourceforge.net/lists/listinfo/jython-users
|