when you make reference to the "this" construct it is a object reference to
the current object. So when you pass "this" into the constructor for
AnotherClass you are actually passing a reference to the anonymous
ActionLister class. To solve the problem try this.

        public class ThisClass {
            AnotherClass  aClass;
             ...
            someJButton.addActionListener(new ActionListner() {
               public void actionPerformed(ActionEvent e) {
                     aClass = new AnotherClass(ThisClass.this);
               }
            });
        .....
}

Because the class itself is anonymous and has no name that is where the
"ThisClass.7" comes from. Java numbers anonymous classes :)

Furthermore there are strict rules on what scoped variables an anonymous
class can access too so be careful there as well.

Hope this helps

Rob Masters
Sun Certified Java Programmer
Sun Certified Java Developer

Comcare Australia
(w) 02 6275 0632
(f) 02 657 4045
[EMAIL PROTECTED]
http://www.comcare.gov.au

> -----Original Message-----
> From: Howard Lee [SMTP:[EMAIL PROTECTED]]
> Sent: August 24, 1999 14:58
> To:   [EMAIL PROTECTED]
> Subject:      Anonymous Class
>
> Hi Java Gurus,
>
> I created a simple anonymos ActionListener  and inside it I call a
> function with the class as a parameter.
>
> ====
>
> public class ThisClass {
>     AnotherClass  aClass;
>      ...
>     someJButton.addActionListener(new ActionListner() {
>        public void actionPerformed(ActionEvent e) {
>              aClass = new AnotherClass(this);
>        }
>     });
> .....
> }
>
> public class AnotherClass {
>     ThisClass _class;
>     public AnotherClass(ThisClass aClas) {
>          _class = aClas;
>      }
> }
>
> And when I tried to compile it, I was getting an error message something
> like type casting error "can't convert ThisClass.7 to ThisClass".
>
> What puzzles me is this "7". What am I doing wrong? I've been pulling my
> hair and can't figure out what I'm doing wrong here. Any help will be
> greatly appreciated. Thanks!
>
> howard
>

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to