This discussion is archived
2 Replies Latest reply: May 9, 2012 3:10 AM by 936009 RSS

Wrong image refresh in java applet AND Windows 7

936009 Newbie
Currently Being Moderated
I'm managing since few days a java applet that takes an image from an industrial product and shows it in a browser (simple web server).
There is following issue: the image is not correctly loaded and refreshed in its own window if just opened but only if the applet is running on Windows 7. The issue is solved as soon as I reduce the window to icon (minimize) and then resize it. I'm looking into java documentation on how to manage the image rendering, maybe I have to override some update or redraw method more, but it is taking time and I'm still learning. NOTE that the window opened does show the issue only when the windows size is not completely shown in the monitor.
Meanwhile I'm wandering if some of you faced and solved similar problem.
Thank you in advance,
Elena
  • 1. Re: Wrong image refresh in java applet AND Windows 7
    Nitin Khare Expert
    Currently Being Moderated
    Can you mention how you are drawing the image and what methods you override? Looks like an issue related to image repaint. The two methods which you should be dealing with are
    public void paint(Graphics g) {
        // called when applet refresh is required by an action from outside the applet. Full applet screen redrawn in this case.
    }
    
    public void update(Graphics g) {
        // called when the action that requires a screen refresh comes from within the applet so that instead of full applet screen redraw 
        // only part of it can be redrawn. One way of overriding it is to simply call paint.
        paint(g);
    }
    Now we never need to call these methods directly from our code. Instead if we are doing anything that requires applet screen to be refreshed then we simply call repaint().

    Hope it helps.

    Thanks,
    Nitin
  • 2. Re: Wrong image refresh in java applet AND Windows 7
    936009 Newbie
    Currently Being Moderated
    Thank you Nitin for your quick reply!
    These are the calling of the functions in the code. As you can see, before to show the image, we are managing a zoom/unzoom by mouse wheel and an addition of writings data on the image itself. All is working fine except on W7:


    public void paint(Graphics g)
    {
         //System.out.println("[ImageFrame::paint my paint!!!]");
         this.PaintImage(g);
    }

    public void update(Graphics g)
    {
         // System.out.println("[ImageFrame::update]");
         this.repaint();
    }

    public void PaintImage(ImageInfo imageInfo, float fps)
    {
         if (imageInfo != null)
         {
              if (this.getImageInfoRef() == null){
                   this.setVisible(true);
              }

              this.setTitle("Image Viewer (" + imageInfo.bufferedImage.getWidth() + "x" + imageInfo.bufferedImage.getHeight() + ") ");
              this.resizeImageFrame((int) (imageInfo.bufferedImage.getWidth() * zoomFactor), (int) (imageInfo.bufferedImage.getHeight() * zoomFactor));
              this.lastFps = fps;
              this.setImageInfoRef(imageInfo);
              //System.out.println("this.getWidth(): " + this.getWidth() + " this.getHeight(): " + this.getHeight() + " zoomFactor: " + zoomFactor);////
              this.PaintImage(this.getGraphics());
         }
    }

    public synchronized void PaintImage(Graphics g)
    {
         ImageInfo locImageInfo = getImageInfoRef();
         if (locImageInfo != null)
         {
              try
              {
                   this.resizeImageFrame((int) (locImageInfo.bufferedImage.getWidth() * zoomFactor), (int) (locImageInfo.bufferedImage.getHeight() * zoomFactor));

                   BufferedImage bufferedImage = this.resizeBufferedImage(locImageInfo.bufferedImage, zoomFactor);

                   this.overlayCodeInfo(bufferedImage, locImageInfo.decInfoStruct, zoomFactor);
                   this.overlayPointerInfo(bufferedImage, locImageInfo.scaling, zoomFactor, this.crossX, this.crossY);
                   this.overlayFrameRateInfo(bufferedImage, this.lastFps);

                   Image img = Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
                   boolean retdraw;
                   retdraw = g.drawImage(img, frameUpperBondarySizeX, frameUpperBondarySizeY, this);
              }
              catch (Exception ex)
              {
                   System.out.println("[ImageFrame::PaintImage] Exception: " + ex);
              }
         }
    }


    Thank you again
    Elena

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points