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!");

}

}

[2825 byte] By [ardmorea] at [2007-11-27 11:07:24]
# 1

And your question/problem/error message/etc is?

ChuckBinga at 2007-7-29 13:21:56 > top of Java-index,Java Essentials,New To Java...
# 2

justListening on 2947

User program running

after I select a file then click the x in debugger console, printout come in

Hello you are lucky

ardmorea at 2007-7-29 13:21:56 > top of Java-index,Java Essentials,New To Java...
# 3

my goal is retrieve the file name.

ardmorea at 2007-7-29 13:21:56 > top of Java-index,Java Essentials,New To Java...
# 4

> Listening on 2947

> User program running

What does that have to do with the application you are writing?

warnerjaa at 2007-7-29 13:21:56 > top of Java-index,Java Essentials,New To Java...
# 5

my propose:

How can I use JFileChooser to get a full

file path & file name for use with a RandomAccessFile?

I know how to display the JFileChooser and that is not the problem.

I also know how to use RandomAccessFile

I need to know how to use the two together. Specifically geting a path from the JFileChooser and

using that path to create a RandomAccessFile.

ardmorea at 2007-7-29 13:21:56 > top of Java-index,Java Essentials,New To Java...