how to split few classes in file to few files

hello!....
part of  my program....

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]);
        }
      });
      
    listOutput.addItemListener(new ItemListener(){
      public void itemStateChanged(ItemEvent e){
        int[] indexes=listOutput.getSelectedIndexes();
      for(int i=0;i<indexes.length;i++)
           listInput.select(indexes[i]);
      }
    });

    btnDel.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent e){
       int[] index=listOutput.getSelectedIndexes();
      while(index.length>0){
          listInput.remove(index[0]);
        listOutput.remove(index[0]);
        //after removing an item refresh the list
        index=listOutput.getSelectedIndexes();  
        listLen();
      }
      }
    });

as i compile ,let say my filename KK, it will have few class file name KK$1.calss, KK$2.class and KK$3.class

it make me can't upload my file to internet...

How to split it in order no more $ appear?
bhuey_lingAsked:
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.

JodCommented:
The $ is used when you have inner classes - your listeners are inner classes (and anonymous inner classes at that) so 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]);
   }
      });

create KK$1.class.

Can you not just rename the files, upload them and then rename them back once they are on the server?

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

listInput.addItemListener(this);
listOutput.addItemListener(this);
btnDel.addActionListener(this);

public void itemStateChanged(ItemEvent e){

      //in here use e.getSource to
      // decide whether to execute the code for listinput or listoutput
      if ( e.getSource().getClass().isInstance(listInput.Class) ) {
            // do listinput
      } else {
            // do  listoutput
      }
   }

public void actionPerformed(ActionEvent e){
  int[] index=listOutput.getSelectedIndexes();
  while(index.length>0){
     listInput.remove(index[0]);
     listOutput.remove(index[0]);
     //after removing an item refresh the list
     index=listOutput.getSelectedIndexes();  
     listLen();
  }
}

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.
0

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
Jan LouwerensSoftware EngineerCommented:
Why can't you upload multiple .class files? Perhaps you can put them all in a single .jar file and upload that?
0
bhuey_lingAuthor Commented:
hello!

bcoz it say my filename have "$" so can upload those file with filename have"$"

what is .jar file?

thnx
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

bhuey_lingAuthor Commented:
Jod..
hello!

i had been tried but have few problem:
this is part of my program:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Analogue_3 extends Applet{
......
btnDel.addActionListener(this);
.....
 
error occur: imcompatible type for method. Explicit cast needed to convert Analogue_3 to java.awt.event.ActionListener

i can't use:
if ( e.getSource().getClass().isInstance(listInput.Class) ) {
bcoz error occur that not class method in List
so i change to:

if ( e.getSource()==listInput){...}

it have no compile error but i dun know it can run or not because can't "appletviewer" yet........

thnx
0
heyhey_Commented:
replace
public class Analogue_3 extends Applet{

with
public class Analogue_3 extends Applet implements ItemListener, ActionListener{

0
JodCommented:
Sorry I should have explained in full. When I said

>> You can avoid it by making your main class the listener and doing this...

I meant what hethey_ has said above. So use...

public class Analogue_3 extends Applet implements ItemListener, ActionListener{

Just out of interest, have you tried renaming the files to KK_1.class, upload them all and then renaming them back? Packaging them in a jar file could also help, but you need to ensure that the ja tool actually includes the relevant inner classes - it won't neccesarily find them automatically unless you specifically mention them.
0
JodCommented:
Here is another example from Sun...

import java.lang.reflect.*;

public class DumpMethods {
  public static void main(String args[])
  {
    try {
      Class c = Class.forName(args[0]);
      Method m[] = c.getDeclaredMethods();
      for (int i = 0; i < m.length; i++)
        System.out.println(m[i].toString());            
    }
             
    catch (Throwable e) {
      System.err.println(e);
    }
  }
}


Invoke this program with a class name like this:

java DumpMethods java.util.Stack

0
JodCommented:
Sorry, posted that in the wrong place....doh!
0
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
Java

From novice to tech pro — start learning today.