Java Reference
In-Depth Information
L ISTING D.6 Continued
/**
* open up a single-file choice dialog returning the chosen FileContent file
*/
public FileContents openFileDialog(String param1, String[] notSupported)
throws java.io.IOException {
JFileChooser jfc = new JFileChooser(param1);
jfc.showOpenDialog(null);
jfc.setMultiSelectionEnabled(false);
return new FileContentsImpl(jfc.getSelectedFile());
}
/**
* open up a multiple file choice dialog returning the chosen FileContent
files
*/
public FileContents[] openMultiFileDialog(String parm1, String[] parm2)
throws java.io.IOException {
JFileChooser jfc = new JFileChooser();
jfc.setMultiSelectionEnabled(true);
jfc.showOpenDialog(null);
int filesN = jfc.getSelectedFiles().length;
FileContentsImpl[] result = new FileContentsImpl[filesN];
for (int i = 0; i < filesN; i++) {
result[i] = new FileContentsImpl(jfc.getSelectedFiles()[i]);
}
return result;
}
}
FileSaveServiceImpl
This service implementation (reported in Listing D.7) provides file save by means of user
authorization. See the example (class Test later in Listing D.11) for a practical example of use.
L ISTING D.7 The FileSaveServiceImpl Class
package com.marinilli.b2.ad.util;
import javax.jnlp.FileSaveService;
import javax.jnlp.FileContents;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.File;
Search WWH ::




Custom Search