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.
Thanks!
jeannieyeapAsked:
Who is Participating?
 
JodConnect With a Mentor Commented:

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++)
      listOutput.select(indexes[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.

OR

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

listInput.addItemListener(this);
listOutput.addItemListener(this);
btnDel.addActionListener(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:

http://codeguru.developer.com/java/tij/tij0081.shtml
0
All Courses

From novice to tech pro — start learning today.