Results 1 to 4 of 4
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default reading dir in java applets

    Hello there,
    I canīt make this the following methode to work inside a applet it wont give me the dir. and not even one of the panes.
    please give me a hint

    Willemjav


    private void readImageFilelist(String dirname) { // gets the list of images
    directory = new File(dirname);
    if (directory.isDirectory() == false) {
    if (directory.exists() == false)
    JOptionPane.showMessageDialog(infoPane," there is no directory called " + directory);
    else
    JOptionPane.showMessageDialog(infoPane, directory + " is not a directory.");
    }
    else {
    JOptionPane.showMessageDialog(infoPane, directory + " it works");
    files = directory.list(); // stores the list of file names
    Imagearray = new Image[files.length];
    for (int i = 0; i < files.length; i++) {
    String str = files[i];
    Imagearray[i] = downloadImage(str); // stores each image in a array for display
    }

    }

    }

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,062
    Rep Power
    8

    Default

    dear hardwired

    I did read some articles about security and I am aware of that issue concerning applets. Thanks for sending me that link anyway. I wrote a small slide show application for use on my web-site. Photos are present in a file folder called Imagestore and the applet should look for them on the server and download the content of the folder into the applet (I AM NOT TRYING TO ENTER A CLIENT ENVIRONMENT). The method (see bottom) reads simply the file directory of the file Imagestore and stores it into an array, which I copy into an image array for display. The application version works perfect but not the applet. The problem is the following method (when left out, the applet works okay). I do not understand which security issue is involved here. The panes should give me some feedback but they don&#180;t.... the applet refuses to popup and I do not know way?

    willem

    private void readImageFilelist(String dirname) { // gets the list of images
    directory = new File(dirname);
    if (directory.isDirectory() == false) {
    if (directory.exists() == false)
    JOptionPane.showMessageDialog(infoPane," there is no directory called " + directory);
    else
    JOptionPane.showMessageDialog(infoPane, directory + " is not a directory.");
    }
    else {
    JOptionPane.showMessageDialog(infoPane, directory + " it works");
    files = directory.list(); // stores the list of file names
    Imagearray = new Image[files.length];
    for (int i = 0; i < files.length; i++) {
    String str = files[i];
    Imagearray[i] = downloadImage(str); // stores each image in a array for display
    }

    }

    }


    and for display

    public void paintComponent(Graphics g) {

    if (Imagearray != null) {
    count++;
    if (count==Imagearray.length)
    count = 0;
    g.drawImage(Imagearray[count],0,0,getWidth(), getHeight(), this);
    }
    else
    g.drawImage(testimage,0,0,getWidth(), getHeight(), this);


    }

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    Applets are much happier using a URL than a File for loading images. For more about this try the tutorial page How to Use Icons with special attention to the section Loading Images Using getResource and possibly Loading Images Into Applets.

Similar Threads

  1. reading URL using java through proxy server
    By asheesh in forum Networking
    Replies: 16
    Last Post: 04-25-2010, 02:15 PM
  2. Does OS intervene when reading Java text files
    By Tina G in forum Advanced Java
    Replies: 1
    Last Post: 04-07-2008, 02:29 PM
  3. using java applets for dag & drop interface
    By frea in forum New To Java
    Replies: 0
    Last Post: 03-27-2008, 08:31 PM
  4. reading textfile from java problem
    By saytri in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 02:13 AM
  5. Question abt.reading xml file using java
    By gvi in forum Advanced Java
    Replies: 6
    Last Post: 11-08-2007, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •