No return value.
I am going to select a file by JFileChooser, then return file or file name. but no return at all unless I click the x icon on debug console .
Thanks
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.io.File;
publicclass FileSelection
{
public File getFile()
{
// display file dialog, so user can choose file to open
final JFileChooser fileChooser =new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
JFrame frame =new JFrame();
int result = fileChooser.showOpenDialog(frame);
// if user clicked Cancel button on dialog, return
if( result == JFileChooser.CANCEL_OPTION)
System.exit(1);
File fileName = fileChooser.getSelectedFile();// get selected file
// display error if invalid
if ((fileName ==null) || (fileName.getName().equals("")))
{
JOptionPane.showMessageDialog(frame,"Invalid File Name","Invalid File Name",JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
return fileName;
}
}
import java.io.*;
import javax.swing.JFrame;
publicclass FileDemo
{
publicstaticvoid main(String args[])
{
FileSelection c =new FileSelection();
File name = c.getFile();
if(name.exists())
System.out.println("Hello you are lucky");
else
System.out.println("Sorry, retry!");
}
}

