Solved

inner classes within applets

Posted on 2000-05-11
9
190 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
javap bin 2 40
Html Table Looping (part 2) 5 27
collection output issue 9 36
Need Help! Getting a syntax error and don't understand why 3 31
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

791 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