开发者

How edit File to MyFile [closed]

开发者 https://www.devze.com 2023-03-04 15:56 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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>();
0

精彩评论

暂无评论...
验证码 换一张
取 消