From: Adam B. <ada...@gb...> - 2001-04-05 00:47:47
|
Er, no. In Java, protected methods are available to subclasses*. Private and "package" (unprefixed methods, eg void myMethod()) level methods and attributes are not. I'd read the Java Tutorial available on the Java website if you don't want to buy a book. If you do want to buy a book I'd recommend Java In A Nutshell. * They are also available within a package, but this is dodgy, I'd stay away from it. Adam Burke > -----Original Message----- > From: cindy [SMTP:inf...@pi...] > Sent: Thursday, April 05, 2001 10:11 PM > To: D-Man > Cc: Jyt...@li... > Subject: Re: [Jython-users] A big problem for me! > > 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? > Wayne > > > D-Man wrote: > > > On Wed, Apr 04, 2001 at 11:01:51PM -0400, cindy wrote: > > | > The following code worked for me : > > | > > > | > from java.awt import Component , AWTEvent > > | > > > | > class C( Component ) : > > | > def __init__( self ) : > > | > self.super__enableEvents( AWTEvent.WINDOW_EVENT_MASK ) > > | > > | Ok. So this means that ever time I wanted to use this method, > "enableEvents()" I > > | have to > > | inherit Component. But lets say that I would like to extend some other > > | component, like > > | JFrame. Then if I want to use enableEvents() in the same class that I > want to > > | extend > > | JFrame, I would have to inherit Componet and do a composit on JFrame. > Is this > > | correct? > > > > Not quite. If you look at the top of the documenation for JFrame you > > will see > > > > Class JFrame > > > > java.lang.Object > > | > > +--java.awt.Component > > | > > +--java.awt.Container > > | > > +--java.awt.Window > > | > > +--java.awt.Frame > > | > > +--javax.swing.JFrame > > > > JFrame already inherits from java.awt.Component. The term "is-a" is > > often used with inheritance. A JFrame object is-a Component object. > > If you inherit from JFrame, you are indirectly inheriting from > > Component. > > > > If you look farther down on the documentation page you will see a list > > of "Methods inherited from Frame" and "Methods inherited from Window" > > and ... and "Methods inherited from Component". Since the methods are > > listed there, they exist in objects of the type "JFrame". > > > > FYI, the documentation (for JDK1.2.2) is at > > > > http://java.sun.com/products/jdk/1.2/docs/api/index.html > > > > while the JFrame page is > > > > http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/JFrame.html > > > > -D > > > > _______________________________________________ > > Jython-users mailing list > > Jyt...@li... > > http://lists.sourceforge.net/lists/listinfo/jython-users > > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > http://lists.sourceforge.net/lists/listinfo/jython-users |