3 Replies Latest reply: Apr 5, 2010 7:17 PM by Darryl Burke RSS

    How to display images that are in Temp folder?

    843807
      Hello,

      I have to display images that reside in Temp folder (java.io.tmpdir). I was able to run below code without any issue as a standalone program.
      But when I embed this applet in jsp, is then the issue popped up.

      1. I have copied files from temp folder to codebase (getCodeBase())
      2. Iterated through codebase and added to the panel.

      But when I embed this on jsp the code base has been changed(its obvious!). Is there any way that I can pull up images directly from user's temporary directory? If so how can I give the path for getImage() method?
           //Show the images from code base on the applet.
           String codeBase = getCodeBase().toString();
           System.out.println("codebase "+codeBase);
           File preview = new File(codeBase);
           File[] previewList = preview.listFiles();
           if (null != previewList) {
                for (int i = 0; i < previewList.length; i++) {
                     File imageFile = new File(previewList.getName());
                     if (previewList[i].getName().startsWith(imageIdTag)) {
                     String fullFileName = codeBase + imageFile;
                     img = getImage(getCodeBase(), previewList[i].getName());
                     previewPanel = new ImagePanel();
                     previewPanel.setImage(img);
                     add(previewPanel);
                     checkbox[i] = new Checkbox(previewList[i].getName(), null,false);
                     add(checkbox[i]);
                     }
                }
           }
      Please help.
      
      R.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
        • 1. Re: How to display images that are in Temp folder?
          793415
          -Ram- wrote:
          ..I have to display images that reside in Temp folder (java.io.tmpdir).
          Which temp folder? The temp folder on the server, or on the client?
          .. I was able to run below code without any issue as a standalone program.
          But when I embed this applet in jsp, is then the issue popped up.
          The way you wrote that suggests to me that you are way out of your depth when working with applets.
          • 2. Re: How to display images that are in Temp folder?
            843807
            The issue with the way I was trying: getImage() was expecting a URL and I have the images in Client temporary folder.

            I have fixed this with an alternative approach. By using ImageIO
            Here it is
            //Show the images from temporary folder on the applet.
                 File preview = new File(tempdir);
                 File[] previewList = preview.listFiles();
                 if (null != previewList) {
                      for (int i = 0; i < previewList.length; i++) {
                           File imageFile = new File(previewList.getName());
                           if (previewList[i].getName().startsWith(imageIdTag)) {
                                String path = tempdir+previewList[i].getName();
                                BufferedImage image = ImageIO.read(new File(path));
                                previewPanel = new ImagePanel();
                                previewPanel.setImage(image);
                                add(previewPanel);
                                checkbox[i] = new Checkbox(previewList[i].getName(), null,false);
                                add(checkbox[i]);
                                }
                           }
                      }
            But I have another issue here. The preview images are only getting visible in the frame when I resize the frame (or) when I double click on the frame to maximize it. 
            Why is this happening?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
            • 3. Re: How to display images that are in Temp folder?
              Darryl Burke
              The preview images are only getting visible in the frame when I resize the frame (or) when I double click on the frame to maximize it.
              Why is this happening?
              Because you don't know the correct way to [perform custom painting|http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html].

              db