From: cindy <inf...@pi...> - 2001-04-05 15:03:43
|
Thanks, Thanks, and Thanks. I notice in the example below that your inheritance was different than mine. I did "from java.awt import swing" I changed it to "import javax" and modified my class statement to look like D- Man's example. Bingo, it works. Wayne D-Man wrote: > On Thu, Apr 05, 2001 at 08:10:50AM -0400, cindy wrote: > | I thought I couldn't access the method enableEvents() by inheriting JFrame. > | The reason being is that this method is protected. I concluded that I have to > | inherit Component to get access to this mrthod. Therefore, the tree structure > | below and inheritance from JFrame wouldn't work for the method enableEvents(). > | > | Is this correct? > > Mostly. 'protected' (in Java, it is slightly different in C++) means > that only subclasses and classes in the same package can access it. > JFrame is a subclass of Component, and your class is a subclass of > JFrame, therefore your class is a subclass of Component. You are > correct up to the point where you say "inheritance from JFrame > wouldn't work". > > If you've done some work in discrete math or logic this is basically > the following axiom : > > if A -> B and B -> C then A -> C > > Here is an example : > > >>> import javax > >>> import java > >>> class MyFrame( javax.swing.JFrame ) : > ... def __init__( self ) : > ... self.super__enableEvents( java.awt.AWTEvent.WINDOW_EVENT_MASK ) > ... def processEvent( self , event ) : > ... print "got an event" > ... > >>> aframe = MyFrame() > >>> aframe.getContentPane().add( javax.swing.JLabel( "Jython is cool" ) ) > javax.swing.JLabel[,0,0,0x0,invalid,alignmentX=0.0,alignmentY=null,border=,flags > =0,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,horizonta > lAlignment=,horizontalTextPosition=,iconTextGap=4,labelFor=,text=Jython is cool, > verticalAlignment=CENTER,verticalTextPosition=CENTER] > >>> aframe.show() > got an event > >>> got an event > got an event > > This was an interactive interpreter session of mine. As you can see > here, I didn't define getContentPane or setVisible, but they worked. > This is because MyFrame is-a JFrame (is-a JComponent ... is-a > Component ...). Through inheritance, instances of MyFrame ('aframe') > have all of those public and protected members (functions and data). > Also, at the end there you can see that processEvent was called when > the frame was shown, when I gave it the focus (with the mouse) and > when I removed the focus (I clicked in the terminal window to copy the > text from). > > Perhaps the following tutorial sections may help you? > > http://python.org/doc/current/tut/node11.html > > http://www.crosswinds.net/~agauld/tutclass.htm > > HTH, > -D > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users |