Execute
Save
Share
Share link
share
share
share
Team
Public Teams
Comments
0
Created By:
Guest
Title:
Title
Description
Edit
Copy Link
Login
Email *
Password *
Login
OR
Create Account
Screen Name *
Email *
Password *
Retype Password *
Team Access Code
Register
Public CodeBins
HELP
--Select Theme--
Ambiance
Blackboard
Cobalt
Eclipse
Elegant
Erlang-Dark
Lesser-Dark
Monokai
Neat
Night
Rubyblue
Vibrant-Ink
Xq-Dark
New CodeBin
CodeBins Versions
12/01/2015- V.1
Recent CodeBins
View All CodeBins
import javax.swing.*; import java.awt.event.*; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.awt.*; public class JFileChoose_Test extends JPanel implements ActionListener { /** * */ private static final long serialVersionUID = 1L; JButton go; JFileChooser chooser; String choosertitle; String myDirectory; public JFileChoose_Test() { go = new JButton("Choose a Directory."); go.addActionListener(this); add(go); } public void actionPerformed(ActionEvent e) { // Declaring a new file chooser and setting the current directory for a default choice. // Selection mode is set to directories only to ensure no single file can be chosen. chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(".")); chooser.setDialogTitle(choosertitle); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // // disable the "All files" option. // chooser.setAcceptAllFileFilterUsed(false); // if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { System.out.println("getCurrentDirectory(): " + chooser.getCurrentDirectory()); System.out.println("getSelectedFile() : " + chooser.getSelectedFile()); } else { System.out.println("No Selection "); } myDirectory = chooser.getSelectedFile().toString(); getFile(myDirectory); } public Dimension getPreferredSize() { return new Dimension(200, 200); } //Not called in the main yet because I haven't built anything that actually gets // a file path, still figuring that out. However this will go to that directory path // and find the first file containing "DAPI" in its file name. It will then // replace "DAPI" with "GFP" in the recorded string and search for the file // containing that name. It then saves these two file paths for later use. private void getFile(String dirPath) { try { Files.find(Paths.get(dirPath), 1, (path, basicFileAttributes) - > (path.toFile().getName().contains("DAPI"))).forEach( dapiPath - > { Path gfpPath = dapiPath.resolveSibling(dapiPath.getFileName().toString().replace("DAPI", "GFP")); // For some reason this method is not printing out anything. // At this point the program just loops back to the directory selection window. doSomething(dapiPath, gfpPath); }); } catch (IOException e) { e.printStackTrace(); } } //Dummy method does nothing yet. I am first going to test it prints the //correct path. Afterwards it will be built to open the files up and then //run the macro I have created to go through the analysis process private void doSomething(Path dapiPath, Path gfpPath) { System.out.println(dapiPath.toAbsolutePath().toString()); System.out.println(gfpPath.toAbsolutePath().toString()); } public static void main(String s[]) { JFrame frame = new JFrame(""); JFileChoose_Test panel = new JFileChoose_Test(); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.getContentPane().add(panel, "Center"); frame.setSize(panel.getPreferredSize()); frame.setVisible(true); } }
Bottom of Page
In Head
On Load
On Ready
Setting
Validate
Copy
Format
Setting
Validate
Copy
Format
No Doc Type
HTML5
HTML 4.01 Transitional
HTML 4.01 Strict
HTML 4.01 Frameset
XHTML 1.1
XHTML 1.0 Transitional
XHTML 1.0 Strict
XHTML 1.0 Frameset
Copy
Format
Download
×
Code Description
×
Difference of Versions
HTML
CSS
JS
×
JS Error
×
CSS Error
Errors
Warnings
×
JavaScript Setting
JS Libraries:
Chrome Frame 1.0.3
Dojo 1.8.0
Dojo 1.7.3
Dojo 1.7.2
Ext Core 3.1.0
jQuery 1.8.0
jQuery 1.7.2
jQuery 1.6.0
jQuery 1.5.0
jQuery 1.4.4
jQuery 1.4.0
jQuery-min 1.7.2
jQueryUI-min 1.8.21
MooTools more-1.4.0.1-full
MooTools core-1.4.5-full
MooTools core-1.4.1-full
Prototype 1.7.1.0
script.aculo.us 1.9.0
SWFObject 2.2
Twitter Bootstrap 2.0.4
WebFont Loader 1.0.28
yui 3.5.1
User Libraries:
Upload File
JavaScript URL(s):
×
CSS Setting
CSS Libraries:
jQueryUI 1.8.21
Twitter Bootstrap 2.0.4
User Libraries:
Upload File
CSS URL(s):