Solved

inner classes within applets

Posted on 2000-05-11
9
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 3

Expert Comment

by:Laminamia063099
ID: 2804167
No problem, I'll check it out on Monday.
0
 

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tomcat: Unable to run tomcat service. 2 30
Java 8 to Java 6 8 33
DTD and JAVA versions 1 33
Java array 21 88
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

730 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