Multiple file uploads with applet

N

news.amnet.net.au

Hi

I would like to upload several files from a FileDialog box at once and
posted a message about this not so long ago.

I was referred to java.awt.FileDialog or javax.swing.JFileChooser and I
wrote something that worked.

However, it only works if you run the program from the command line as it
uses JFrame. This means you cannot run it as a client from within your
browser.

Therefore what is needed is an applet that sits on the client side and lets
the client select several files on the desktop machine which can be uploaded
to the server. I need it to be simple so I can integrate it with my code and
cannot really use any of the complex ones that can be downloaded.

I successfully compiled an applet with JFileChooser in it, but I could not
avoid starting a Frame as well. When I try to run the applet in my browser,
it does nothing (just a grey box). Is this because you cannot start a Frame
in an applet? Or do I need start and paint methods? When I add:

public void paint(Graphics g) {
msg = "I am inside the paint method";
g.drawString(msg,10,30);
}

I get an error "Could not resolve symbol "Graphics".

Can anyone tell me what is wrong with my applet and what I need to do to
make it work? I am not that familiar with applets.

Here is the full code:

import javax.swing.*;
import java.io.*;
import java.applet.*;

public class FileChooserApplet extends Applet {

public void init () {

JFrame parentFrame = new JFrame("File Chooser");
JFileChooser chooser = new JFileChooser();

chooser.setMultiSelectionEnabled(true);
chooser.setDialogTitle("File Chooser");
int result = chooser.showOpenDialog(parentFrame);
if (result == JFileChooser.APPROVE_OPTION) {
File[] selectedFiles = chooser.getSelectedFiles();
int length = selectedFiles.length;

if (length > 0) {
for (int i = 0; i < length; i++) {

// Here I would like to load the filename I get from
File[] into
// an Arraylist, then return the ArrayList to my jsp
// However, how to return the ArrayList from
// this void method I am not sure. Any suggestions?

}

}

}

}
}

Any help will be greatly appreciated.

Thanks very much

Hugo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top