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?
 
JodConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.