Solved

inner classes within applets

Posted on 2000-05-11
9
187 Views
Last Modified: 2013-11-23
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.





0
Comment
Question by:simonm99
  • 5
  • 4
9 Comments
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2801739
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 :)
0
 
LVL 3

Accepted Solution

by:
Laminamia063099 earned 50 total points
ID: 2801743
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 :)
0
 

Author Comment

by:simonm99
ID: 2803542
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.
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2804167
No problem, I'll check it out on Monday.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:simonm99
ID: 2816388
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.



0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2816657
Good luck!

Laminamia :)
0
 

Author Comment

by:simonm99
ID: 2817423
yes, I recreated it, and yes I reported it. It amazes me that this got through testing.
0
 

Author Comment

by:simonm99
ID: 2843899
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.
0
 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2844406
Gotta love Microsoft :)

Laminamia
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now