-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileChooser.java
40 lines (34 loc) · 1.05 KB
/
FileChooser.java
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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.*;
public class FileChooser
/*
* By: Evan NG
* ICS4U0-D1
* 323058826
*/
{
private static String fileName;
public static void chooseFile()
{ // creates a file chooser so the user can choose a file from his/her library.
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("TXT Files", "txt");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
//System.out.println("You chose to open this file: " + chooser.getSelectedFile());
fileName = chooser.getSelectedFile().getAbsolutePath();
}
}
public static String getFile()
/*
* This method returns the File that the user has choosen.
*/
{
chooseFile();
return fileName;
}
}