About the inner class

Hi, i am doing a web page, which there have some java applet in it. i write the java applet where i found that i use many inner class files on it, that mean i found that there have a symbol "$" in the name of the inner class files. i use the addXXXListener( ) methods.
 My problems are all the java applet, i have to upload it to server, so what should i do ? How to solve the problem of the "$" in the name of the inner class files. Please tell me step by step (more details)to solve it.
 Another question is that no matter what methods i use that make the class files occur "$", is that the solution apply for all? If not, please tell me more details to do if i not using the addXXXListener () methods.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


In general, the $ is always used when you have inner classes - your listeners are inner classes (and probably anonymous inner classes at that) so they for a class file named KK they appear as KK$1.class and so on...

So for example...

listInput.addItemListener(new ItemListener(){
     public void itemStateChanged(ItemEvent e){
        int[] indexes=listInput.getSelectedIndexes();
        for(int i=0;i<indexes.length;i++)

inside class KK is created as create KK$1.class.

There are two ways to avoid this.

You may be able to just rename the files, upload them and then rename them back once they are on the server.


You can avoid the inner classes by making your main class the listener and doing this...


So, to make your main class the listener you just make it implement the interface you are listening on (such as MouseListener, ActionListener etc.)

public myClass implements ActionListener, etc...{

      public void itemStateChanged(ItemEvent e){
        //process your item changed event here

      public void actionPerformed(ActionEvent e){
        //process your Action event here


then add the methods that would normally be in your listener class into your main class like above. You will then only have one class file named myClass.class and it will internally have all the code necessary to process the events.

Gets a bit more messy without inner classes I'm afraid...there are possible other ways to do this but the above will work nicely and leave you with just one class.

Here is an explanation of the basics that may help you:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.