I need to create a gui application.. When the user clicks the start button use a JFileChooser to allow them to pick a directory from the system and then run the recursive search of the file system from that directory and display the directory and each file in the JTextArea.
Here is what I have... My problem is that I cant get the directory or files to print in the JTextArea.. Can someone please help me? Here is my action code.
Thanks
public void actionPerformed(ActionEvent evt)
{
//which button
if (evt.getSource() == quitButton)
{
System.exit(0);
}
else if (evt.getSource() == openButton)
{
//create a filechooser
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION){
chooser.getCurrentDirectory();}{
File dir = new File("");
File[] children = dir.listFiles();
if(children == null){
//either directory does not exit or is not a directory
}else{
for (int i=0; i<children.length; i++){
//get filename of file or directory
File fileName = children[i];
}
}
resultArea.append(chooser.getName());
}
}
}
}
//create the inheritance to each button
FileSearchListener buttListener = new FileSearchListener();
openButton.addActionListener(buttListener);
quitButton.addActionListener(buttListener);
}
}