JFileChooser in Applet

Hi all,
I'm having a hard time using JFileChooser in Applet. I was trying implemented custom Filefilter so that the certain files to show up on the chooser dialog, but when I add the line, addChoosableFileFilter() method, the applet didn't come out. The applet initialized Ok, and the message "applet started" appeared on the browser, but the file-choosing dialog never comes out. I checked the Java console, but there's no useful message on it. Even, I expected some error message on it. Then, it seems be hopeless to find the errors on this applet since virtually I got no errors!?
Does anybody have good explanations why the chooser dialog didn't come out on the applet window? Here is a piece of code for JFileChooer and the FileFilter:
/* FileChooser */
public class UploaderApplet extends JApplet
public void init() {
try {
final JFileChooser chooser = new JFileChooser();
//when I add this line below, the filechooser didn't come out
chooser.addChoosableFileFilter(new FormCDNFilter());
Container contentPane = getContentPane();
contentPane.add(chooser, BorderLayout.CENTER);
chooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (cmd.equals(JFileChooser.APPROVE_SELECTION)) {
File file = chooser.getSelectedFile();
.....do something with chosen file here
/* FileFilter */
public class FormCDNFilter extends FileFilter {
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
String extension = Utils.getExtension(f);
if (extension != null) {
if (extension.equals(Utils.fae) ||
extension.equals(Utils.ovd) ||
extension.equals(Utils.pmd) ||
extension.equals(Utils.psf)) {
return true;
} else {
return false;
return false;
}

Sorry, but you can't use a JFileChooser in an applet by security reasons. You probably get a security exception in the java console. I'm still looking a way to open text files for the server. If you have an ideia, please let me know.

Similar Messages

  • JFileChooser in Applet hangs ie7 and vm

    Hello
    First of all, excuse my poor english.
    In my website I have a problem with an applet.
    This applet is used to select files from the client computer.
    My JRE version is 1.5.0_10 Java HotSpot(TM) Client VM
    The browser is IE 7
    The OS is WinXP SP2
    First time the page is loaded works fine, but when the page is reloaded it crashes when it makes a new instance of JFileChooser.
    This hangs the ie and the vm.
    I've tried it in other computer that uses the 1.5.0_07 and ie 7, and it works fine.
    This is the code:
    shpFileChooser = new javax.swing.JFileChooser();
    shpFileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
    int retOutbox = shpFileChooser2.showOpenDialog(null);
    if(retOutbox==JFileChooser.APPROVE_OPTION){
    path = shpFileChooser2.getSelectedFile().getPath();
    else {
    path = "";
    Please Help me.

    I'm also have the problem with JFileChooser spiking the CPU in an applet -- with JRE 6 Update 2, which I just installed (did not happen with Update 1).
    When new JFileChooser() is hit, the CPU usage spikes to 100% for about 15 seconds until the control appears. Then as I navigate through folders, I get a similar spike for each click.
    This is happening for both IE7 and FireFox 2.0.0.5 on WinXP SP2.
    Any insights are much appreciated.

  • Opening JFIleChooser in applet

    Hi,
    I was clogged up with opening a JFileChooser in an applet.
    The way i have done is as follows :
    I have taken a Button and added it to an JApplet.. In the listener class for that button i have written the code for opening the JFileChooser and selecting the file.. This is working fine if i was running to using appletviewer . I am getting the problem when i was running using Internetexplorer. It is throwing out some security exception. SO how to avoid the problem.
    Bye

    Thanks a lot for your response! However, where can I find out about signed applet?? Is there any information on this Java site somewhere??

  • JFileChooser in Applet keeps focus after selection of a directory

    I have spent several days on the following issue, but haven't found any solution so far...
    When I open a JFileChooser out of an Applet and select a Directory, the FileChooser closes as expected, but a text field located on the main applet pane cannot be selected any more (the mouse pointer goes to "text cursor" style when hovering over it, but the text field does not get the focus when clicked). Strangely, the other button on the same pane still reacts to mouse clicks. This happens only when I select a directory, but not when I choose a file. Also, it does not happen, when I click "Cancel" instead of "Open". Furthermore, the problem occurs only using the Firefox plugin, not in the AppletViewer. I even tried to remove the text field from the root pane and add a new one after the file chooser execution, but still it won't regain focus.
    Here's the stripped-down code:
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    public class TestApplet extends JApplet {
        private static final long serialVersionUID = 1L;
        @Override
        public void init() {
            final JPanel rootPanel = new JPanel();
            rootPanel.setLayout(new BorderLayout());
            getContentPane().add(rootPanel);
            final JButton fileChooserButton = new JButton("Start");
            fileChooserButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.setAcceptAllFileFilterUsed(false);
                    fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                    fc.setMultiSelectionEnabled(false);
                    fc.showOpenDialog(rootPanel);
            JTextField textField = new JTextField();
            rootPanel.add(fileChooserButton, BorderLayout.CENTER);
            rootPanel.add(textField, BorderLayout.SOUTH);
    }And this is the applet.html:
    <applet code="TestApplet.class" codebase="file://home/administrator/workspace/Test/bin" width=100 height=50></applet> This concerns: Ubuntu 9.04 / Firefox 3.6.9 / JVM 1.6.0_20
    Any help or ideas for a workaround would be much appreciated...

    AndrewThompson64 wrote:
    JWS was available as a separate download since Java 1.2. It became bundled with the JRE around 1.4.2, not sure of the micro-version, but it was in the 1.4 era. 1.4 has been relegated to the 'obsolete' pile now, so I think you are safe expecting the end user to be prepared to update to 1.5+ if needed.You don't know my grandma: she isn't prepared to anything, but she wants things to just work ;-)
    For ensuring the user has a minimum of 1.5, see the [Java&#153; Rich Internet Applications Deployment Advice|http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html] for details of the deployJava.js script. It is useful for both applets and apps. deployed using JWS.
    Yes, I already use this script for my Applet, but I hadn't realized that it worked for JWS as well.
    Do you mean like a corporate intranet?Exactly. Another example could be centrally managed laptops connecting over Internet to your application (like the traveling salesman connecting to his task planner)
    ... Can you do a search of the bug DB and if nothing shows up, submit one? The only chance these things will get fixed is if they are reported.I agree with you on that question and I've already had a look (didn't find anything so far)
    Embedded applets are a PITA. I wouldn't disagree, but again, if you want to bring a rich client to the masses, sometimes that's the way to do it (unless you go for ActiveX, which is definitely not an option for me). Anyway, I'll give JWS a try.. and then I'll ask the customer help desk if it was a good idea...
    For example, is there any programmatic way to determine if the embedded applet is not acting as expected? If so, monitor that and on detection, pop a dialog to the user explaining the situation and offering the free floating version from a button click.Well, I have to think a bit more about this. Probably I will just to check if the text field gets the focus after a mouse click, by adding some kind of test inside a MouseListener. If it doesn't get the focus, I would be quite sure that there's a problem... I'll look into this.
    On the other hand, to work around the whole problem, I have found some Open Source Directory Chooser (http://sourceforge.net/projects/jfolderchooser), which looks nice at a first glance, but I didn't have the time to go into it in more detail. I'll just quote you here:
    I cannot say if this will fix the problem. Or perhaps it will fix the problem in that browser/JRE combo., but break it in another. ;)Words full of truth :)

  • JFileChooser Problem when "Automatic Configuration" is enabled on IE

    Hi,
    I have JFileChooser Based Applet dialog. When i enable the "Automatic Configuration" in my LAN setting on IE. The windows based shortcuts e.g. Desktop,"My documents" dont show up correctly directories they contain. They only show a part of them.
    Could you please help me out in figuring out the same.
    Thanks,
    Amit

    Sevket,
    b When The " Update Complete. OK to Disconnect " Show On iTunes:
    Click On the Little " EJECT " Button Beside The iPod icon (in the iTunes Source List)... The iPod will Disappear From the Source list.. Then Unplug Your iPod.
    i I suggest you To Charge Your iPod Throught Power Adaptor For WAll. That, if You have One.
    M.

  • Applet with JFilechooser called from a Javascript blocks paint messages

    Hi,
    I am trying to create an applet that can:
    1) be called from a Javascript
    2) displays a file selection dialog for multi-selecting files
    3) returns the selected filenames in a string to the JavaScript
    I am able to use doPrivileged to apply the necessary security context to launch a JFilechooser and return the filenames selected. However, When the JFilechooser dialog is visible and the user moves the dialog window around the HTML pages dose not receive any repaint messages. They seem to be blocked by the thread that launched the JFilechooser dialog and is probably blocking update events as the dialog is still visible.
    I know I need some type of a message pump so the child thread can inform the parent thread and the browser to repaint. However, I don't know how to do this.
    Please help.
    ------Applet Code Begin:-----
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.AWTEvent;
    import java.awt.event.AWTEventListener.*;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.util.Locale;
    import java.util.MissingResourceException;
    import java.util.Properties;
    import java.util.ResourceBundle;
    import java.util.Vector;
    import javax.swing.JApplet;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    public class SampleApplet extends JApplet
       boolean allowDirs=false;
       boolean allowFiles=true;
       boolean hidden=false;
       File lastUserDir=null;
       public void init()
        public void start()
        public void stop()
        public String selectFiles()
           String choosenFiles = null;
           choosenFiles = new String((String)java.security.AccessController.doPrivileged(
           new java.security.PrivilegedAction()
         public Object run()
            String choosenFiles=new String();
                 JFilechooser fc = new JFilechooser();
         fc.setFileSelectionMode(allowDirs ? (allowFiles ? JFileChooser.FILES_AND_DIRECTORIES
            : JFileChooser.DIRECTORIES_ONLY)
            : JFileChooser.FILES_ONLY);
         fc.setMultiSelectionEnabled(true);
                 int returnVal = fc.showOpenDialog(null);
                 if (returnVal == JFileChooser.APPROVE_OPTION)
                    choosenFiles = "The selected filesnames will be stuffed here";
              return choosenFiles; //return whatever you want
           return choosenFiles;   
    ------Applet Code End:-----
    ------Html Code Begin:-----
    <html>
    <applet id="SampleApplet" archive="SampleApplet.jar"; code="SampleApplet.class"; width="2" height="2" codebase=".">
    </applet>
    <head>
        <title>Untitled Page</title>
    <script language="javascript" type="text/javascript">
    function SelectFiles_onclick()
      var s = (document.applets[0].selectFiles());
      alert(s);
    </script>
    </head>
    <body>
        Click Test button to select files
        <input id="SelectFiles" type="button" value="Select Files" onclick="return SelectFiles_onclick()" />
    </body>
    </html>
    ------Html Code End:-----

    try this:
    first don't open the file dialog in the SelectFiles call. Start a new thread that does that. Then return from the SelectFiles call immediately. Now after the user selectes the files call back into the javascript by doing something like this:
    pass the list of files into this function, each on being a String in the params array
        public synchronized void sendDataToUI(Object[] params) {
            if (FuserState.hasQuit()) {
                return;
            String function = "getUpdates";
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "Calling Javascript function " + function);
            if (getJavaScriptWindow() == null) {
                logger.log(Level.SEVERE, "Member javascriptWindow is NULL, no call was made!");
                return;
            try {
                getJavaScriptWindow().call(function, params);
            catch (netscape.javascript.JSException x) {
                if (params == null) {
                    logger.log(Level.SEVERE, "p=NULL PARAM");
                } else {
                    logger.log(Level.SEVERE, "p=" + params[0]);
        protected JSObject getJavaScriptWindow() {
            javascriptWindow = JSObject.getWindow(this);
        }

  • JFileChooser applet doesn't work on all platforms

    We have a signed Java applet which works perfectly on Windows XP and Linux but malfunctions on Windows 7 and MacOS 10.5.
    The part which does not work is opening up a JFileChooser (which opens up fine) which then permits the user to browse local files only but not folders on network drives. When the user double-clicks on a network folder or clicks the Open button, nothing happens. The folder is not opened and there are no exceptions reported in the console.
    Obviously it presents as some kind of security violation/exception but, as I said, there are no exceptions in the console and it works fine on some OSes but not others. I have examined the permissions on a folder that does open and one that doesn't (i.e. a network folder) and they certainly are different but I can't spot any obvious problems. All machines have the exact same version of Java (i.e. 1.6.0_20) and it doesn't appear to a 32-bit vs. 64-bit issue as there is a mix of architectures that are working and not working.
    Can anyone suggest how I might go about debugging this or perhaps suggest a resolution? Given that the code that is being executed at the time is Swing code and not application code I am at a bit of a loss as to how to solve this problem.
    The Logical Animal

    It could be the JFileChooser code is being altered or displayed on a thread other than the EDT. OTOH that more typically manifests as a random bug on instances of the application on all platforms/JREs.

  • Can applet have JFileChooser?

    i am trying to develop an applet. but i can't implement the Jfilechooser in the applet, i wonder whether that is even possible in the first place?
    tim

    thanks but i have done something similar but i have got something like
    java.security.AccessControlException:access denied, and i can't solve it. i have enclose my problem below, and those with **** i guess it may have something to do with that. not sure
    many many many thanks for your help.
    tim
    ============================================
    public class TSP extends Applet implements ActionListener, MouseListener{
    public void actionPerformed(ActionEvent e){
    if(e.getSource() == inputFile && openFile()){
    //do whatever i want
    public boolean openFile() {
    //open the file chooser
    int returnVal = fChooser.showOpenDialog(TSP.this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
    tspSF = fChooser.getSelectedFile();
    System.out.println(tspSF.getName()+" is chosen");
    **** inputFile = new Input(this, errHandler);
    inputFile.readandinputdata(tspSF);
    return true;
    else return false;
    public init(){......}
    ==========================================
    public class Input{
    public Input(TSP tsp, ErrHandler errHandler){
    **** this.tsp = tsp;
    this.errHandler = errHandler;
    // method readandinputdata
    public void readandinputdata(File tspSF){
    try {
    input = new BufferedReader(new FileReader(tspSF));
    catch....
    try {
    //read in the first line
    data = input.readLine();
    while (data != null){
    st = new StringTokenizer(data);
    nodeNumber = tokenChanger.parseInt(st.nextToken());
    x = tokenChanger.parseInt(st.nextToken());
    y = tokenChanger.parseInt(st.nextToken());
    //store the x and y with some method in TSP class
    **** tsp.storeNodes(x, y);
    // read next time
    data = input.readLine();
    }// end of while data != null
    closeFile();
    } // end of second scan
    catch.....
    }//end of readandinoputdata
    }

  • Trying to Imitate the html POST  method with an applet

    I am trying to imitate the POST method with an applet, so that I can eventually send sound from a microphone to a PHP script which will store it in a file on a server. I am starting out by trying to post a simple line of text by making the PHP script think that it is receiving the text within a POST-ed file. The reason I am doing things this way is in part because I am, for the time being, limited to a shared server without any support for servlets or any other server side java.
    The code I am trying is based in part on an old thread found elsewhere in this forum, concerning sending data to a PHP file by imitating the POST method:
    link:
    http://forum.java.sun.com/thread.jspa?threadID=530399&messageID=2603608
    someone named "harmmeijer" provided most of the answers on that thread. If that person is still around hope they take a look at this,also I have some questions to clarify what they said on the other thread..
    My first attempt at code is below. The applet is in a signed jar file and is trying to pass a text line to the PHP script in the same directory and on the same server that the applet came from. It is doing this by sending header information that is supposed to be identical to what an html form would send if it was uploading a .txt file with the line of text within it. The applet displays one button. When you press it, it sucessfully starts up the postsim method (defined at the end), which is supposed to send the info to the PHP script at the server.
    I have two questions:
    1) I know that the PHP script is starting up, because it prints out a few messages depending on what happens. However, the script does not recognize any file coming down the line, so it does not save anyting on the server, and prints out a message saying the no file was uploaded.
    Any idea what might be going wrong? I'm not getting any error messages from the applet. I've tried a few different variations of the 'header' information contained in the line:
    osToServer.writeBytes("--****4353\r\nContent-Disposition: form-data; name=\"testfile\"; filename=\"C:testfile.txt\"\r\nContent-Type: text/plain\r\n");
    The commented out line below it shows one variation (which was given in the thread mentioned above).
    2) You'll notice that I've commented out the two lines having to do with the input line:
    //InputStream isFromServer;
    and
    //isFromServer = uc.getInputStream();
    The reason is that the program crahes whenever I put the latter line in - to the extent that Opera closes down the JVM and then crashes when I tried to exit it.. I must be doing something horribly wrong there! I first tried using isFromServer = new DataInputStream(uc.getInputStream());
    becuase it was consistent with the output stream, but that caused the same problem.
    Here's the code:
    public class AudioUptest1 extends Applet{
    //There are a few spurious things defined in this section, having to do with the fact the microphone data is evenuatly going to be sent. haven't yet insterted code to get input from a microphone.
    AudioFormat audioFormat;
    TargetDataLine targetDataLine;
    SourceDataLine sourceDataLine;
    DataOutputStream osToServer;
    //InputStream isFromServer;
    URLConnection uc;
    final JButton captureBtn = new JButton("Capture");
    final JPanel btnPanel = new JPanel();
    public void init(){
    System.out.println("Started the applet");
    try
    URL url = new URL( "http://www.mywebsite.com/handleapplet.php" );
    uc = url.openConnection();
    //Post multipart data
    uc.setDoOutput(true);
    uc.setDoInput(true);
    uc.setUseCaches(false);
    //set request headers
    uc.setRequestProperty("Connection", "Keep-Alive");
    uc.setRequestProperty("HTTP_REFERER", "http://applet.getcodebase");
    uc.setRequestProperty("Content-Type","multipart/form-data; boundary=****4353");
    osToServer = new DataOutputStream(uc.getOutputStream());
    //isFromServer = uc.getInputStream();
    catch(IOException e)
    System.out.println ("Error etc. etc.");
    return;
    //Start of GUI stuff
    captureBtn.setEnabled(true);
    //Register listeners
    captureBtn.addActionListener(
    new ActionListener(){
    public void actionPerformed(
    ActionEvent e){
    captureBtn.setEnabled(false);
    //Postsim method will send simulated POST to PHP script on server.
    postsim();
    }//end actionPerformed
    }//end ActionListener
    );//end addActionListener()
    add(captureBtn);
    add(btnPanel);
    // getContentPane().setLayout(new FlowLayout());
    // setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(250,70);
    setVisible(true);
    }//end of GUI stuff, constructor.
    //These buffers might be made larger.
    byte tempOutBuffer[] = new byte[100];
    byte tempInBuffer[] = new byte[100];
    private void postsim(){
    System.out.println("Got to the postsim method");
    try{
    //******The next four lines are supposed to imitate a POST upload from a form******
    osToServer.writeBytes("--****4353\r\nContent-Disposition: form-data; name=\"testfile\"; filename=\"C:testfile.txt\"\r\nContent-Type: text/plain\r\n");
    //osToServer.writeBytes("Content-Disposition: form-data; name=\"testfile\"; filename=\"C:testfile.txt\"\r\nContent-Type: text/plain\r\n");
    //This is the text that's cupposed to be written into the file.
    osToServer.writeBytes("This is a test file");
    osToServer.writeBytes("--****4353--\r\n\r\n");
    osToServer.flush();
    osToServer.close();
    catch (Exception e) {
    System.out.println(e);
    System.out.println("did not sucessfully connect or write to server");
    System.exit(0);
    }//end catch
    }//end method postsim
    }//end AudioUp.java

    Hi All,
    I was trying to write a signed applet that helps the
    user of the applet to browse the local hard disk and
    select a file from the same. The JFileChooser class
    from Swing is what I used in my applet. The problem
    is with the policy file. I am not able to trace the
    exact way to write a policy file which gives a total
    access to read,write,delete,execute on all the drives
    of the local hard disk.
    I am successful in signing the applets and performing
    operations : read,write,delete & execute on a single
    file but failing to grant permission for the entire
    file.
    Any help would be highly appreciated.Which policy file are you using? there might be more than one policy file.
    also, u have to specify the alias of the signed certificate in the policy file to grant the necessary priviledges to the signed applet.

  • Problems with JFileChooser and Windows 2000 (can't see mydocuments contents

    Hi! I've an applet which has a JFileChooser component. In other Windows, I can select the MyDocuments folder and it goes there and list all the contents OK. But, in Windows 2000, when I go to MyDocuments, none of the contents is listed in the file chooser. I need to navigate through all the directories to get there (C:\documents and settings\user\my documents) and then, it shows its contents, but obviously, I don't want it to be this way because is difficult for the common user.
    Any idea of why is going on this?
    Thanks in advance!

    Hello, You need to use something like o=isp as the
    root DN, then o=yourorg.com goes beneath it.
    i.e.
    For the other questions on setup, just choose o=isp
    as base DN when you set up the directory server. When
    you run ims_dssetup.pl, choose o=internet as the DC
    tree base, then choose o=isp as the user/groups base
    suffix.
    When you are installing messaging server it will ask
    where to put the default organization, this is where
    you would choose o=abc.com, o=isp
    For more info on how this structure works please take
    a look at this link and it will all fit into place:
    http://docs.sun.com/source/816-6017-10/changes.htm#170
    8Alright, I got ims_dssetup to run successfully. But now when the ims 5.2 installation is about 50% done, I get the message:
    A serious problem occurred while installing the iPlanet Messaging Server Messaging SIE entry in LDAP (msg.cfgldap.sie.inf). It reported the following problem:
    The server configuration for the Messaging SIE entry in LDAP (msg.cfgldap.sie.inf) cannot be created.

  • JFileChooser and Read Only Folders in XP

    The following question concerns a Java application, not a applet or web service.
    If you are browsing a folder with JFileChooser the button to create a new folder is disabled if the parent folder is read-only. Under XP folders often show up as read only and cannot be easily changed by the user. Even if Windows reports that the parent folder is read only, it does not block the creation of sub-folders in it. I'd like to always make the create folder button active regardless of whether the parent folder is read only or not; that more truely reflects the folder creation permissions anyway and mimics the behaviour of an MFC file browser. How would I do this?
    I've even tried to add a listener to the file chooser so that as the user browses to a new directory I automatically change the write permissions of folder, but short of a system command, there's no way to change the write permissions from JAVA so I don't consider this a neat solution.
    I'm surprised that I haven't found similar complaints on the net. If you use a MFC file browser the create folder button is active, but a Java file chooser has it disabled for the same folder.
    Please help.

    What would you say to a new FileChooser? I love java but I'm no fan of Sun's choosers. (See www.MartinRinehart.com, Examples, ColorChooser.)
    Email me if you're interested in doing one.

  • Help need in Signed Applets.....Urgent

    Hi,
    I am stuck with a problem. Please help me out.
    The requirement is :
    I have an applet which has to run an executable which produces a .txt. The applet should use this .txt to produce its output.
    I made the applet into a signed jar and ran the executable to produce the .txt . But the .txt is outside the jar file and I am not able to use it to create the result.
    How do I use the .txt now?? Is the method that I am trying proper or should I use some other method?
    Another doubt is, when I run the .html of the applet code (which is in the server), is it cached in the client???

    I made the applet into a signed jar and ran the
    executable to produce the .txt . But the .txt is
    outside the jar file and I am not able to use it to
    create the result.
    How do I use the .txt now??Hand the user a JFileChooser and let him tell you where the file is, or loook at the exe to see whether you can specify an output directory as a parameter.
    Is the method that I am
    trying proper or should I use some other method?It's highly ugly, but I can't think of anything else.
    Another doubt is, when I run the .html of the applet
    code (which is in the server), is it cached in the
    client???Yes. No need to download the same stuff each time. The details are browser-specific.

  • Error on reading file in Applet

    I wrote an jfilechooser and allow the user to choose the folder. The applet will then load the file list of the folder. However, after i chose the folder, the following error occurs
    Exception in thread "AWT-EventQueue-25" java.security.AccessControlException: access denied (java.io.FilePermission C:\Documents and Settings\Developer\My Documents\My Pictures read)I know i shall edit the java.policy file. However, i would like to know how to edit it if i want to allow the applet to access all the file in client's PC.
    Thank you.

    how to sign the applet, any tutorial resources for
    this?
    Yes, it's called the internet.

  • Applet not Working.Why???

    I have written an applet program but it does not work
    It works when i did it as an application.
    I have installed JAVA plug in.The HTML and Applet codes
    are in the same directory as JDK
    The web browser comes up with a grey area & the following messages:
    Exception:java.lang.ClassNotFoundException:testing4.class
    (on the grey area)
    Applet testing4 not loaded (at the bottom of the browser)
    Why is this so?
    The code i have used are as follows:
    HTML CODE
    <html>
    <title>LPC
    </title>
    <applet code="testing4.class"  width=400 height=110>
    </applet>
    </html>APPLET PROGRAM CODE
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    //import java.lang.Object;
    public class testing4 extends JApplet
    { private JTextArea display;
      private JScrollPane scrollPane2;
      private JButton paste;
      private JPanel P2;
      private File fileName;
      public void init()
        paste=new JButton("paste");
        paste.setMinimumSize(new Dimension(90,20));
        paste.setPreferredSize(new Dimension(90,20));
        paste.setMaximumSize(new Dimension(90,20));
        copyhandler pa=new copyhandler();
        paste.addActionListener(pa);
        display=new JTextArea();
        scrollPane2=new JScrollPane(display);
        scrollPane2.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane2.setMinimumSize(new Dimension(200,58));
        scrollPane2.setPreferredSize(new Dimension(200,58));
        scrollPane2.setMaximumSize(new Dimension(200,58));
        P2=new JPanel();
        P2.setMinimumSize(new Dimension(200,80));
        P2.setPreferredSize(new Dimension(200,80));
        P2.setMaximumSize(new Dimension(200,80));
        P2.setLayout(new BoxLayout(P2,BoxLayout.Y_AXIS));
        scrollPane2.setAlignmentX (Component.LEFT_ALIGNMENT);
        P2.add(scrollPane2);
        paste.setAlignmentX(Component.LEFT_ALIGNMENT);
        P2.add(paste);
       Container c=getContentPane();
        c.add(P2);
       //COPIES TEXT FROM FILE ON MY DISK TO THE TEXTAREA
       private class copyhandler implements ActionListener
       { public void actionPerformed(ActionEvent event)
         { JFileChooser fileChooser = new JFileChooser();
           fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
           int result = fileChooser.showOpenDialog(testing4.this);
           // user clicked Cancel button on dialog
           if ( result == JFileChooser.CANCEL_OPTION )
             return;
           fileName = fileChooser.getSelectedFile();
           if ( fileName == null ||
              fileName.getName().equals( "" ) )
           JOptionPane.showMessageDialog( null,"Invalid File Name",
                                            "Invalid File Name",
                                          JOptionPane.ERROR_MESSAGE );
           else
           { try
             { FileReader in = new FileReader(fileName);
               BufferedReader reading= new BufferedReader(in);
               String store="";
               while (reading.ready())
               { StringTokenizer st = new StringTokenizer(reading.readLine());
                 store=store+st.nextToken()+"\n";
               display.setText(store);
             catch ( IOException e )
             { JOptionPane.showMessageDialog( null,
                                          "Error Opening File", "Error",
                                          JOptionPane.ERROR_MESSAGE );
      public static void main (String [] args)
      { testing4 done =new testing4();
        JFrame frame = new JFrame("testing");
        frame.addWindowListener(new WindowAdapter()
                                 public void windowClosing(WindowEvent e)
                                   System.exit(0);
        done.init();
        frame.getContentPane().add(done);
        frame.pack();
        frame.setSize(205,110);
        frame.setVisible(true);
    }

    It Still giving a blank page.
    New Code
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    //import java.lang.Object;
    public class testing4 extends JApplet
    { private JTextArea display;
      private JScrollPane scrollPane2;
      private JButton paste;
      private JPanel P2;
      private File fileName;
      public void init()
        paste=new JButton("paste");
        paste.setMinimumSize(new Dimension(90,20));
        paste.setPreferredSize(new Dimension(90,20));
        paste.setMaximumSize(new Dimension(90,20));
        copyhandler pa=new copyhandler();
        paste.addActionListener(pa);
        display=new JTextArea();
        scrollPane2=new JScrollPane(display);
        scrollPane2.setVerticalScrollBarPolicy(
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane2.setMinimumSize(new Dimension(200,58));
        scrollPane2.setPreferredSize(new Dimension(200,58));
        scrollPane2.setMaximumSize(new Dimension(200,58));
        P2=new JPanel();
        P2.setMinimumSize(new Dimension(200,80));
        P2.setPreferredSize(new Dimension(200,80));
        P2.setMaximumSize(new Dimension(200,80));
        P2.setLayout(new BoxLayout(P2,BoxLayout.Y_AXIS));
        scrollPane2.setAlignmentX (Component.LEFT_ALIGNMENT);
        P2.add(scrollPane2);
        paste.setAlignmentX(Component.LEFT_ALIGNMENT);
        P2.add(paste);
       Container c=getContentPane();
        c.add(P2);
       //COPIES TEXT FROM FILE ON MY DISK TO THE TEXTAREA
       private class copyhandler implements ActionListener
       { public void actionPerformed(ActionEvent event)
         { JFileChooser fileChooser = new JFileChooser();
           fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY );
           int result = fileChooser.showOpenDialog(testing4.this);
           // user clicked Cancel button on dialog
           if ( result == JFileChooser.CANCEL_OPTION )
             return;
           fileName = fileChooser.getSelectedFile();
           if ( fileName == null ||
              fileName.getName().equals( "" ) )
           JOptionPane.showMessageDialog( null,"Invalid File Name",
                                            "Invalid File Name",
                                          JOptionPane.ERROR_MESSAGE );
           else
           { try
             { FileReader in = new FileReader(fileName);
               BufferedReader reading= new BufferedReader(in);
               String store="";
               while (reading.ready())
               { StringTokenizer st = new StringTokenizer(reading.readLine());
                 store=store+st.nextToken()+"\n";
               display.setText(store);
             catch ( IOException e )
             { JOptionPane.showMessageDialog( null,
                                          "Error Opening File", "Error",
                                          JOptionPane.ERROR_MESSAGE );
      public static void main (String [] args)
      { testing4 done =new testing4();
        //you did not set applet's width and height:
        //applet is a container too
        done.setWidth(205);
        done.setHeight(110);
        JFrame frame = new JFrame("testing");
        frame.addWindowListener(new WindowAdapter()
                                  public void windowClosing(WindowEvent e)
                                  { System.exit(0);
        done.init();
        frame.getContentPane().add(done);
        frame.pack();
        frame.setSize(205,110);
        frame.setVisible(true);
    }

  • How to allow user upload file on applet??

    Sorry I'm new to programming here, but I'm trying to allow user to upload a file to the server so the program inside the server can user the file as input.
    I've noticed that JFileChooser, the ideal class for this, is not allowed on the applet, so I don't know how to go about doing this.
    Thanks for any input!

    ok
    you wish to transfer a file from applet to server.
    1. Applet gets the file
    the applet needs to access the file System therefor it must b a signed applet to get aound the security restrictions. This is why the JFileChooser doesn't work. Check out the tutorials on jars and applets, particularly the security notes.
    2. opens a connection with the server
    so the applet has a file and needs to send it. there needs to be a service of some form on the destination computer to execpt the file. Perhaps you write your own perhaps you use HTTP.
    3. server software stores the file
    where an applet is an mini application that runs within the confines of the web browser. a SERVLET is a service program which runs with in the confines of a server, such as a web server.
    this is a lot easier to do HTML rather that applet in my opinion but which ever.

Maybe you are looking for

  • Alpha numeric page numbers

    I would like to number pages using letters and numbers. When I put a number in for section and a letter in for sub-section, I get a message that the sub-section has to be a number. I have tried different variations with volume, chapter, section...ect

  • Saving form created in Acrobat XI so other users cannot edit contents

    I created a form in Acrobat XI and added information to the fields.  I created multiple files, each with different data.  I want users with Reader to be able to see the completed forms using Reader, but not be able to edit the fields.  Hopefully I do

  • Can't Print/Save pdf Files

    Is there an issue with printing/saving pdf files in Snow Leopard?  Do I have to buy Adobe Acrobat 9.1 Pro to do this?  The Adobe website says there are security features in SL which disable the Adobe pdf printer: "The Adobe PDF Printer is not availab

  • Error while trying to load Crystal report via Windows service

    Hi, I am trying to generate PDF file using crystal reports. I have developed a console application which works absolutely fine, however when I converted the code to work as windows service (wcf hosted in Windows service), this below error I see from

  • Nokia lumia 620 automatic switch off

    My lumia is automatically switch off and then i have to open the battery than again place the battery then its only switch on