Skip to content

Instantly share code, notes, and snippets.

@micahrj
Created October 5, 2012 01:20
Show Gist options
  • Select an option

  • Save micahrj/3837509 to your computer and use it in GitHub Desktop.

Select an option

Save micahrj/3837509 to your computer and use it in GitHub Desktop.
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class FileFinder {
public static void main(String[] args) throws Exception {
// Makes the file chooser adopt the standard look for the system
// on which the program is running.
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// Opens a file chooser that only displays directories.
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
String word;
while (true) {
// Displays a file chooser and determines what happened.
int outcome = chooser.showOpenDialog(null);
// If the user selected a file ...
if (outcome == JFileChooser.APPROVE_OPTION) {
// Gets a target word from the user.
word = JOptionPane.showInputDialog("Enter file name: ");
if (word != null) {
JOptionPane.showMessageDialog(null, "hi");
System.exit(0);
}
else {
int stringOption = JOptionPane.YES_NO_OPTION;
JOptionPane.showConfirmDialog(null, "Do you want to continue?", null, JOptionPane.YES_NO_OPTION);
if(stringOption != JOptionPane.YES_OPTION) {
System.exit(0);
}
}
} else {
int stringOption = JOptionPane.showConfirmDialog(null, "Do you want to continue?", null, JOptionPane.YES_NO_OPTION);
if(stringOption != JOptionPane.YES_OPTION) {
System.exit(0);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment