I have a program, it uses a standard class File. The ArrayList. I need to replace your class MyFile and really want to change the collection ArrayList to List .
class MyFile
public class MyFile extends File {
public MyFile(File f) {
super(f, "");
}
Boolean isNetworkFile = false;
}
example function in programm
public void addFile(JFrame frame) {
FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
FileChooser.setFileFilter(filter);
FileChooser.setMultiSelectionEnabled(true);
int fileValid = FileChooser.showOpenDialog(frame);
if (fileValid == javax.swing.JFileChooser.CANCEL_OPTION) {
return;
}
else if(fileValid == javax.swing.JFileChooser.A开发者_运维问答PPROVE_OPTION) {
File[] file = FileChooser.getSelectedFiles();
listSong.addAll(Arrays.asList(file));
}
}
How do it?
Your question is difficult to understand. But I'll take a guess at what you mean. It looks like you'll need a loop, to construct MyFile
instances from File
instances:
File[] files = FileChooser.getSelectedFiles();
MyFile[] myfiles = new MyFile[files.length];
for (int i = 0; i < files.length; i++) {
myfiles[i] = new MyFile(files[i]);
}
As for the collection, an ArrayList
is a List
. You can just do:
List<Blah> list = new ArrayList<Blah>();
精彩评论