-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputController.java
More file actions
39 lines (32 loc) · 1.17 KB
/
FileInputController.java
File metadata and controls
39 lines (32 loc) · 1.17 KB
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
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
public class FileInputController implements ActionListener
{
private Graph graph; //The Model used to describe the game
private JButton fileInputted; //The button component linked to the controller
public FileInputController(Graph aGraph, JButton button)
{
this.graph = aGraph;
this.fileInputted = button;
}
public void actionPerformed(ActionEvent e)
{
// create the dialog box and set up filters for what it displays
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(System.getProperty("user.dir")));
while (true)
{
// show the dialog
int result = chooser.showOpenDialog(null);
if (result == JFileChooser.APPROVE_OPTION)
{
break;
}
else
{
System.out.println("No file selected.");
}
}
}
}