-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSelector.java
More file actions
45 lines (35 loc) · 829 Bytes
/
Copy pathFileSelector.java
File metadata and controls
45 lines (35 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.FileNotFoundException;
import java.util.Scanner;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.filechooser.FileNameExtensionFilter;
public class FileSelector {
final JFileChooser fs = new JFileChooser();
public FileSelector ()
{
}
public Scanner init()
{
while (true)
{
FileNameExtensionFilter filter = new FileNameExtensionFilter("xml files (*.xml)", "xml");
fs.setFileFilter(filter);
int returnVal = fs.showOpenDialog(null);
try
{
if (returnVal == JFileChooser.APPROVE_OPTION)
{
return new Scanner(fs.getSelectedFile());
}
else
{
return null;
}
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, "Invalid File", "error",JOptionPane.ERROR_MESSAGE);
}
}
}
}