Link to home
Start Free TrialLog in
Avatar of simonm99
simonm99

asked on

inner classes within applets

I'm using Sun Java 2 v1.2.2 (think! latest, anyway)

I understand the difference between implementing a KeyListener inteface and creating an inner class which extends KeyAdaptor in that empty methods need not be created in the latter case.
As an exercise I'm trying to create an outer class which contains BOTH KeyAdaptor and MouseAdaptor extended inner classes called K and M for the sake of argument.

I get a compile error whenever I have both K and M defined as innder classes within the outer class source file but as soon as I comment out either one, it compiles fine.

Is there a limit to how many inner classes one can create?

The answer to this is not in any one of my three Java reference books.





Avatar of Laminamia063099
Laminamia063099

Simon:

The following works fine for myself.  I compiled it with the Java SDK 2 (1.3), but it should work fine as well under 1.2.2.  Post the simplified code of your class and the error message that you get when you compile and we'll find out what the problem is.

And no, there is no limit to the number of inner classes that one can create (at least not a limit within our reasonable needs).

import java.awt.event.*;

class Adapters {
      class M extends MouseAdapter{
      }
      class K extends KeyAdapter{
      }
}

Laminamia :)
ASKER CERTIFIED SOLUTION
Avatar of Laminamia063099
Laminamia063099

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of simonm99

ASKER

that has removed the possibilty of a compiler limitation. I'll post the simplified code on monday when I get back.

thanks for answering , I do appreciate it.
No problem, I'll check it out on Monday.
I solved it, the file was called KeyAndMouse.java, the class had KeyAndMouse within its definition.

I finally worked out that "javac keyandmouse.java" didn't compile successfully although "javac KeyAndMouse.java" did compile and work perfectly well.

Obvious, you might say but the javac compiler didn't protest that it couldn't find the file, it just failed to compile it completely unless the parameter filename case was perfect.

Error was about class name not being same as .java filename, which I had thought might be the compiler being confused about multiple inner classes as I renamed the class and file to "fred" and disabled one inner class, which did then work. The error was misleading in that the class name and filename WERE identical - it was the case of the filename passed to javac that was different to the actual classname/filename.

thanks anyway - your comment did help me remove that compiler limitation possibility. I'm thinking of sending this case thing into Sun as a javac bug if I can recreate it.



Good luck!

Laminamia :)
yes, I recreated it, and yes I reported it. It amazes me that this got through testing.
they said it was "Usage error" because their compiler can't deal with case differences in parameters.
They said "Windows is one of the few OSs that doesn't pay attention to case, your problem is a usage error"

muppets.
Gotta love Microsoft :)

Laminamia