Applet Browse button

Hi,I would like to create a browse button in my java applet using AWT that would allow me to browse through windows. Just like any regular browse button. I'm having difficulty finding this ...would anyone know how ?
[230 byte] By [applet_crazya] at [2007-11-27 6:11:16]
# 1
What do you mean by a "browse" button?
paulcwa at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 2
For instance, i want to have a textfield, and right next to it browse button, so that the user can click on browse, search the local drive for a file, click open, and that file path would end up in the textfield right next to a browse button.
applet_crazya at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 3
I'm pretty sure that's what java.awt.FileDialog and javax.swing.JFileChooser are for.Note that if you want to do this in an applet, you're going to have to sign the applet to be able to examine the filesystem.
paulcwa at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 4

I opened the FileDialog, and I'm able to select the file that i want. However When I try to examine the file (FileReader)i get the following in the console window:

This is a block of my code:

fr = new FileReader(fileString);

br = new BufferedReader(fr);

String line = br.readLine();

while (line!=null){ //not EOFSystem.out.println(line + "\n");line = br.readLine();

}

This is what I get in the Console at line fr = new FileReader

Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission C:\Documents and Settings\acheikhali\Desktop\testing.txt read)

at java.security.AccessControlContext.checkPermission(Unknown Source)

at java.security.AccessController.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkPermission(Unknown Source)

at java.lang.SecurityManager.checkRead(Unknown Source)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileInputStream.<init>(Unknown Source)

at java.io.FileReader.<init>(Unknown Source)

at iNetVuBootLoader.fileParser(iNetVuBootLoader.java:289)

at iNetVuBootLoader.actionPerformed(iNetVuBootLoader.java:270)

at java.awt.Button.processActionEvent(Unknown Source)

at java.awt.Button.processEvent(Unknown Source)

at java.awt.Component.dispatchEventImpl(Unknown Source)

at java.awt.Component.dispatchEvent(Unknown Source)

at java.awt.EventQueue.dispatchEvent(Unknown Source)

at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.pumpEvents(Unknown Source)

at java.awt.EventDispatchThread.run(Unknown Source)

This may have something to do with Signing the applet, in which i'm not sure how it is done exactly. Do you know what the problem might be ?

applet_crazya at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 5

Yeah, the problem is that applets are by default not allowed to access the file system. So you got a security exception. Actually I'm surprised that you were even able to see a file.

Apparently if you sign the applet, you can do things like access files. However I've never done this myself so I don't know the details. I believe there's an applet signing tool included in the JDK. You may have to additionally assign specific permissions. Google for tutorials if the docs included with the JDK aren't sufficient.

paulcwa at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 6
Does anyone know how to sign an applet, or just access a file on the local drive from an applet without using a jar file. Just purely through java... also a way such that the end user will not need to do technical script writing.? (at most change the settings of the web browser)..
applet_crazya at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...
# 7
You have to sign it. That's the whole point of having a security manager, that it can't be bypassed.The end user shouldn't have to script anything, although they can probably change the settings on their JVM to alter what the jar file can do, if they want to.
paulcwa at 2007-7-12 17:17:28 > top of Java-index,Desktop,Core GUI APIs...