各位麻烦了,小弟在做一个mp3播放器其中[code]private Vector fileName,dirName,numList; 
[/code]
fileName记录各个文件名,dirName记录各个文件的绝对路径,numList记录在Jlist列表里显示要播放的音乐。现在根据fileName想进行字典排序,相应的改变dirName,然后改变numList,最终重新显示Jlist。在这里我想用冒泡法进行尝试用2种方法来改变Vector fileName的植,但是都没有成功。编译没有错误
但是没有任何显示
[code]public void filesort(){String dirNamecopy=new String();
Object filecompare=new Object();
String[] interspace=new String[fileName.size()];
int i,j;for(i=0;i<fileName.size();i++) 
interspace[i]=fileName.elementAt(i).toString(); for(i=0;i<fileName.size()-1;i++)//冒泡法
for(j=0;j<fileName.size()-i-1;j++)
if(interspace[j].compareTo(interspace[j+1])>0)//string进行比较

   filecompare=fileName.get(j+1)    //用Object来接受get()
   fileName.setElementAt(fileName.elementAt(j),j+1);
   fileName.setElementAt(filecompare,j);
   
   dirNamecopy=dirName.elementAt(j+1).toString(); //用String来接受
   dirName.setElementAt(dirName.elementAt(j),j+1);
   dirName.setElementAt(dirNamecopy,j);
     
}for(i=0;i<fileName.size();i++)
numList.setElementAt((i+1)+"."+fileName.elementAt(i).toString(),i); 
        
list.setListData(numList); 
}[/code]
我知道可以根据[code]Comparator comp=Collections.reverseOrder(); 
Collections.sort(fileName, comp); [/code]可以实现排序 但是我对应的dirName似乎就无从下手了。请问大家这究竟是怎么一回事情呢?先谢谢了

解决方案 »

  1.   

    class MP3Song implements Comparable<MP3Song> {
        private String fileName;
        private String dirName;    public int compareTo(MP3Song song) {
            return this.fileName.compareTo(song.fileName);
        }    // other necessary methods.
    }
      

  2.   

    能否在详细说清楚呢?真的不是很明了,二楼是要我重新写一个比较的方法吗?
    我觉得是setElementAt没有起到作用谢谢了