Solved

Image Update in Applet?

Posted on 2003-12-09
43
1,682 Views
Last Modified: 2013-12-22
Hai ,
 I want to load images dynamically to my applet.
I have four file names..
String fileNames[] = {"test1.png","test2.png","test3.png","test4.png"};

I want to load the images one at a time to my applet I am using the code

public void paint(Graphics g){
            i= (i+1)%4;
            Image img = getImage(getCodeBase(),fileNames[i]);
            g.drawImage(img,0,0,null);
}

Now I have two threads
one will update the images  for every second
     such that the updation will take place in a cycle  ( only one file will be changed at a time..)
Another will call the repaint()

I can able to see that the images are updated by another thread but the updated images are not loaded by the applet insted the images that were present at the time of starting the applet is repeated.

How can i get the updated images into the Applet.

Thanks
Narayanaswamy
0
Comment
Question by:Narayanaswamy
  • 17
  • 13
  • 9
  • +1
43 Comments
 
LVL 2

Expert Comment

by:Tols
Comment Utility
Try this:

g.drawImage((new ImageIcon(fileNames[i]).getImage(),0,0,null);
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
Sorry - error in brackets:

g.drawImage((new ImageIcon(fileNames[i])).getImage(),0,0,null);

0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
Generally, do not override paint(Graphics g) method but paintComponent(Graphics g) method instead.
I suppose variable i is global..
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Thanks Tols
I tried this but still it happens the Same...

One thread is updating the images.

If i close and reopen the applet then The new images are comming but not updated corresponding to another thread...



Narayanaswamy
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
How this tread update images?
0
 

Author Comment

by:Narayanaswamy
Comment Utility
I now tried
public void paintComponents(Graphics g){
            i= (i+1)%4;
            //Image img = getImage(getCodeBase(),fileNames[i]);
            g.drawImage((new ImageIcon(fileNames[i])).getImage(),0,0,null);
      }

Still the result is the same....


The code i used in threads are...

The thread that calls repaint ....
public void run(){
      while(isRunning){
            repaint();
            try{Thread.sleep(100); }catch(Exception e){}
      }
}


The thread that updats the Image
public void run(){
             Toolkit toolkit = Toolkit.getDefaultToolkit();
              Dimension screenSize = toolkit.getScreenSize();
              Rectangle screenRect = new Rectangle(screenSize);
              Robot robot ;
      String filePath = "c:\\Img\\";
      int i=0;
      while(true){
            i= (i+1)%4;
            robot = new Robot();
            BufferedImage image = robot.createScreenCapture(screenRect);
            // save captured image to PNG file
                                 try{
            writeToFile(image, filePath+fileNames[i]);
            Thread.sleep(1000);}catch(Exception e){
                                        System.out.println(e);
                                 }
      }
}
public synchronized  void writeToFile(BufferedImage  image,String fileName) throws Exception{
      
      ImageIO.write(image, "png", new File(fileName));
}

0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
Do You really need to save images to files?
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Yes

The images has to be saved into file and from file only I need to load to the Applet

Thanks
Narayanaswamy
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
?
;-)

I suppose this application is a part of (or test) for another project...
Link above may be usefull.
0
 

Author Comment

by:Narayanaswamy
Comment Utility
I tried this
Still the result remains the same....

public void paintComponents(Graphics g){
            i= (i+1)%4;
            //Image img = getImage(getCodeBase(),fileNames[i]);
            g.drawImage(Toolkit.getDefaultToolkit().getImage(fileNames[i]),0,0,null);
      }


Narayanaswamy
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
?
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
Try to As URL give full addres of server and path to file (like in web browser).
0
 

Author Comment

by:Narayanaswamy
Comment Utility
I tried that also but the result is same..

I found one more thing.

I stopped the Image capturing Thread
Now only The thread that repaints is running....

I started the applet.
The 4 images appeared one by one.

"  While the applet is running .... I deleted the four images ..."  
then also the applet is showing the images ( even if the images are not there) I thinks as told in the link it is not refreshed.

From this I guess that the class file doesn't look for the image at the run time so that only it is not taking the new image( updated by another thread previously)

But i am not sure about what is happening originally ( even if the file is not there the applet is displaying  the image...??)

How to solve this...?

Narayanaswamy


0
 
LVL 2

Accepted Solution

by:
Tols earned 100 total points
Comment Utility
Images are buffered in applet's local space (on client's machine)
It's needed to force JVM to reload them from server.
Maybe downloading images by URLConnection will solve this.

It may look like this:
//..............
URL url;
try
{
      url = new URL("http", "serverURL", "fileName");
      URLConnection con = (URLConnection) url.openConnection();
      con.setUseCaches(false);
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      DataInputStream dis = new DataInputStream(con.getInputStream());
      int b = -1;
      while ((b = dis.read()) != -1)
            buffer.write(dis.read());
      Image img = (new ImageIcon(buffer.toByteArray())).getImage();
      dis.close();
} catch (Exception e)
{
      e.printStackTrace();
}
//................
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Thanks for the comment
I will now try this...

Narayanaswamy
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
First of all you load the images every time the applet is repainted, are you sure you want that?
Second, the loading of the image is made assincronusly so you need to use the MediaTracker for that. I guess if you use ImageIcon, will be ok, but better thru MediaTracker
Third, the thread which make the repaint call should be sinchronized with the thread which loads the images, otherwise you have to fast repaint calls and the images still not updated.

I will have more to say aboutthis, if you will post a short example to work on.
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Thans Ovi

Yes I want to load images everytime the applet is repainted..

Now i am trying Tols coding..
I have already pasted the coding above..

The thread that calls repaint remains inside the Applet but the thread that updates the Image remains outside the Applet.

You have mentioned about MediaTracker... May I know how to use that in this sitiuation.....

Narayanaswamy

0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
MediaTracker tracker = new MediaTracker(this); //this = the applet
tracker.addImage(img, 0);
tracker.waitForId(0);
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Taken from API docs:

public class MediaTracker
extends Object
implements Serializable
The MediaTracker class is a utility class to track the status of a number of media objects. Media objects could include audio clips as well as images, though currently only images are supported.

To use a media tracker, create an instance of MediaTracker and call its addImage method for each image to be tracked. In addition, each image can be assigned a unique identifier. This identifier controls the priority order in which the images are fetched. It can also be used to identify unique subsets of the images that can be waited on independently. Images with a lower ID are loaded in preference to those with a higher ID number.

Here is an example:



--------------------------------------------------------------------------------

 import java.applet.Applet;
 import java.awt.Color;
 import java.awt.Image;
 import java.awt.Graphics;
 import java.awt.MediaTracker;

 public class ImageBlaster extends Applet implements Runnable {
      MediaTracker tracker;
      Image bg;
      Image anim[] = new Image[5];
      int index;
      Thread animator;

      // Get the images for the background (id == 0)
      // and the animation frames (id == 1)
      // and add them to the MediaTracker
      public void init() {
          tracker = new MediaTracker(this);
          bg = getImage(getDocumentBase(),
                  "images/background.gif");
          tracker.addImage(bg, 0);
          for (int i = 0; i < 5; i++) {
            anim[i] = getImage(getDocumentBase(),
                      "images/anim"+i+".gif");
            tracker.addImage(anim[i], 1);
          }
      }

      // Start the animation thread.
      public void start() {
          animator = new Thread(this);
          animator.start();
      }

      // Stop the animation thread.
      public void stop() {
          animator = null;
      }

      // Run the animation thread.
      // First wait for the background image to fully load
      // and paint.  Then wait for all of the animation
      // frames to finish loading. Finally, loop and
      // increment the animation frame index.
      public void run() {
          try {
            tracker.waitForID(0);
            tracker.waitForID(1);
          } catch (InterruptedException e) {
            return;
          }
          Thread me = Thread.currentThread();
          while (animator == me) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                break;
            }
            synchronized (this) {
                index++;
                if (index >= anim.length) {
                  index = 0;
                }
            }
            repaint();
          }
      }

      // The background image fills the frame so we
      // don't need to clear the applet on repaints.
      // Just call the paint method.
      public void update(Graphics g) {
          paint(g);
      }

      // Paint a large red rectangle if there are any errors
      // loading the images.  Otherwise always paint the
      // background so that it appears incrementally as it
      // is loading.  Finally, only paint the current animation
      // frame if all of the frames (id == 1) are done loading,
      // so that we don't get partial animations.
      public void paint(Graphics g) {
          if ((tracker.statusAll(false) & MediaTracker.ERRORED) != 0) {
            g.setColor(Color.red);
            g.fillRect(0, 0, size().width, size().height);
            return;
          }
          g.drawImage(bg, 0, 0, this);
          if (tracker.statusID(1, false) == MediaTracker.COMPLETE) {
            g.drawImage(anim[index], 10, 10, this);
          }
      }
 }
 
0
 

Author Comment

by:Narayanaswamy
Comment Utility
// The Applet code I used is

import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.ImageIcon;
import java.net.*;
import java.io.*;

public class  ImgApplet extends Applet{
      PaintThread p = null;
      String fileNames[] = {"test1.png","test2.png","test3.png","test4.png"};
      int i=0;
      public void init(){
            p = new PaintThread();
      }
      public void paintComponents(Graphics g){
            i= (i+1)%4;
            URL url;
            try{
                   url = new URL(getCodeBase(),fileNames[i]);
                 URLConnection con = (URLConnection) url.openConnection();
                 con.setUseCaches(false);
                 ByteArrayOutputStream buffer = new ByteArrayOutputStream();
                 DataInputStream dis = new DataInputStream(con.getInputStream());
                 int b = -1;
                 while ((b = dis.read()) != -1)
                          buffer.write(dis.read());
                 Image img = (new ImageIcon(buffer.toByteArray())).getImage();
                    g.drawImage(img,0,0,this);
                 dis.close();
            } catch (Exception e){
                 e.printStackTrace();
            }
      }

      public void destroy(){
            p.stopRun();
            try{Thread.sleep(3000); }catch(Exception e){}
      }
      class PaintThread  implements Runnable{
            boolean isRunning = true;
            Thread t;
            public PaintThread(){
                  t = new Thread(this);
                  t.start();
            }
            public void run(){
                  while(isRunning){
                        repaint();
                        try{Thread.sleep(100); }catch(Exception e){}
                  }
            }
            public void stopRun(){
                  isRunning = false;
            }
      }
}

/*
<applet code="ImgApplet" width=400 Height=400></applet>
*/




The thread that updates the image is
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

public class  ServerImg{
      public static void main(String[] args) throws Exception{
            // determine current screen size
            Toolkit toolkit = Toolkit.getDefaultToolkit();
            Dimension screenSize = toolkit.getScreenSize();
            Rectangle screenRect = new Rectangle(screenSize);
            // create screen shot
            Robot robot ;
            String fileNames[] = {"test1.png","test2.png","test3.png","test4.png"};
            String fileURL = "f:\\Test\\";
            int i=0;
            while(true){
                  i= (i+1)%4;
                  robot = new Robot();
                  BufferedImage image = robot.createScreenCapture(screenRect);
                  // save captured image to PNG file
                  writeToFile(image, fileURL+fileNames[i]);      
                  try{Thread.sleep(1000);}catch(Exception e){}
            }
      }
      public synchronized static void writeToFile(BufferedImage  image,String fileName) throws Exception{
            ImageIO.write(image, "png", new File(fileName));
      }
}


Still I am not getting the Image

Narayanaswamy
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Narayanaswamy
Comment Utility
I am getting the Red coloured rectangle in the code that uses MediaTracker


Narayanaswamy
0
 
LVL 9

Assisted Solution

by:Ovi
Ovi earned 25 total points
Comment Utility
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.ImageIcon;
import java.net.*;
import java.io.*;

public class  ImgApplet extends Applet{
     PaintThread p = null;
     String fileNames[] = {"test1.png","test2.png","test3.png","test4.png"};
     int i=0;
     Image backBuffer = null;

     public void init(){
          p = new PaintThread();
     }
     public void paint(Graphics g){
        if(backBuffer == null) {
              backBuffer = createImage(getSize().width, getSize().height);
           }
       Graphics g1 = backBuffer.getGraphics();
          i= (i+1)%4;
          try{
               Image img = (new ImageIcon(new URL(getCodeBase(),fileNames[i]))).getImage();
                 g1.drawImage(img,0,0,this);
          } catch (Exception e){
               e.printStackTrace();
          }
        g.drawImage(backBuffer, 0, 0, getSize().width, getSize().height, this);
     }

     public void destroy(){
          p.stopRun();
          try{Thread.sleep(3000); }catch(Exception e){}
     }
     class PaintThread  implements Runnable{
          boolean isRunning = true;
          Thread t;
          public PaintThread(){
               t = new Thread(this);
               t.start();
          }
          public void run(){
               while(isRunning){
                    ImgApplet.this.repaint();
                    try{Thread.sleep(100); }catch(Exception e){}
               }
          }
          public void stopRun(){
               isRunning = false;
          }
     }
}

//****************************************************************************

import java.io.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;

public class  ServerImg{
     public static void main(String[] args) throws Exception{
          // determine current screen size
          Toolkit toolkit = Toolkit.getDefaultToolkit();
          Dimension screenSize = toolkit.getScreenSize();
          Rectangle screenRect = new Rectangle(screenSize);
          // create screen shot
          Robot robot ;
          String fileNames[] = {"test1.png","test2.png","test3.png","test4.png"};
          String fileURL = System.getProperty("user.dir");
          int i=0;
          while(true){
               i= (i+1)%4;
               robot = new Robot();
               BufferedImage image = robot.createScreenCapture(screenRect);
               // save captured image to PNG file
               writeToFile(image, fileURL + File.separator +fileNames[i]);    
               try{Thread.sleep(1000);}catch(Exception e){}
          }
     }
     public synchronized static void writeToFile(BufferedImage  image,String fileName) throws Exception{
          ImageIO.write(image, "png", new File(fileName));
     }
}
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
I think the problem is that applet do not reload image files from server. If image file changes on the server side applet will not reload it from file but from cache on client side.
Solution will be to force reload image fom file on server.

Maybe try this thing with URLConnection but instead of calling 'getCodeBase()' use an url address stright.
getCodeBase() probably returns an local address where applet is downloaded on client machine.

What getCodeBase() method returns?
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Try my code, on my side is working fine.

Just a tought, the applet should not be used to perform havy operations (loading the images). I would put this job on the update thread and use the applet just to update the view with the current image.
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Dear Oci,
I am getting this error...
java.lang.NullPointerException
        at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:48)
        at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:715)
        at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2782)
        at sun.awt.image.ImageRepresentation.drawToBufImage(ImageRepresentation.
java:726)
        at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:722)
        at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:147)
        at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2782)
        at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2772)
        at ImgApplet1.paint(ImgApplet1.java:29)
        at java.awt.Container.update(Container.java:1289)
        at sun.awt.RepaintArea.paint(RepaintArea.java:169)
        at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
        at java.awt.Component.dispatchEventImpl(Component.java:3587)
        at java.awt.Container.dispatchEventImpl(Container.java:1582)
        at java.awt.Component.dispatchEvent(Component.java:3368)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:191)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
sun.awt.image.PNGImageDecoder$PNGException: bogus length: -1
        at sun.awt.image.PNGImageDecoder.getChunk(PNGImageDecoder.java:714)
        at sun.awt.image.PNGImageDecoder.getData(PNGImageDecoder.java:727)
        at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:249)
        at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.j
ava:254)
        at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:168)
        at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
sun.awt.image.PNGImageDecoder$PNGException: bogus length: -1
        at sun.awt.image.PNGImageDecoder.getChunk(PNGImageDecoder.java:714)
        at sun.awt.image.PNGImageDecoder.getData(PNGImageDecoder.java:727)
        at sun.awt.image.PNGImageDecoder.produceImage(PNGImageDecoder.java:249)
        at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.j
ava:254)
        at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:168)
        at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)


And Image is not refreshing....
Narayanaswamy
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
what about mine?
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Dear Tols,
When i use the URL in my local system It printed access denied
When i put  that to server it printed
getCodeBase() prints

http://sys07/Narayana/test2.png

Narayanaswamy
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
Have you tried the code I've sent you?
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Hai Ovi
I am trying both the codings..
  First it shows that error then It loads the images..

but they are not refreshed...
When updated by another thread

Narayanaswamy
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
they are on my side.

The errors you are getting is because the thread which does the screen capture is not sinchronyzed with the applet. One will write and other one will read. This can result in conflict if the png header is not correctly written by the first.
0
 
LVL 9

Expert Comment

by:Ovi
Comment Utility
they are on my side.

The errors you are getting is because the thread which does the screen capture is not sinchronyzed with the applet. One will write and other one will read. This can result in conflict if the png header is not correctly written by the first.

I will suggest you to take the screen captures only at the applet request. You will save in this way alot of resources. Currently the system you have is working pretty bad, and consumes alot of processor.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You just need to cycle through the images. The following is tested to do that, but you will have to work your screen capturing code into. Incidentally, the applet will have to be signed or the security policy altered in order to write those files.


/*
<applet codebase="." code="ImageCycle.class" width="300" height="300">
</applet>
*/


import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.MediaTracker;



public class ImageCycle extends Applet implements Runnable {
      private int imageIndex;
      private Image[] images;
      public static final String[] FILE_NAMES = { "test1.png","test2.png","test3.png","test4.png" };
      public static final int DELAY = 1000;

      public void init() {
            try {
                  images = new Image[FILE_NAMES.length];
                  MediaTracker mt = new MediaTracker(this);
                  for(int i = 0;i < FILE_NAMES.length;i++) {
                        Image img = getImage(getCodeBase(), FILE_NAMES[i]);
                        mt.addImage(img, i);
                        mt.waitForID(i);
                        images[i] = img;
                  }
            }
            catch(Exception e) {
                  e.printStackTrace();
            }
      }

      public void start() {
            new Thread(this).start();
      }

      public void paint(Graphics g) {
            g.drawImage(images[imageIndex], 0, 0, this);
      }

      public void run() {
            for(;;) {
                  imageIndex++;
                  imageIndex %= FILE_NAMES.length;
                  try {
                        Thread.sleep(DELAY);
                  }
                  catch(InterruptedException e) {
                        /* ignore */
                  }
                  repaint();
            }
      }
}
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Hai Ovi,
  Now it is not showing the error...
 The Images are loading but not refreshed..
It displays only the images that are present at the time of starting the applet..

The changed images are not displayed..


Narayanaswamy
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
CEHJ, as I understood Narayanaswamy wants to change files on server side, then load it in aplet on client side - multiple times the same filename.
The files are changing.
;-)
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Hai CEHJ

Thanks for your comment.
This will cycle the Images but the images will be keep one changing...
I will try your coding
And let you know the result.

Narayanaswamy
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
OK - so the problem is now one of not seeing the changed images is it?
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Yes Tols
The same I want to do..?

Now I am getting the problem of not refreshing... in the client side ( applet)
but the images are updated on the server...

Narayanaswamy



0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You could probably load the images in a separate thread. This would make a URLConnection to the server and check the last-modified header. If it's changed from before it should fetch it or leave the image in the array untouched.
0
 
LVL 2

Expert Comment

by:Tols
Comment Utility
But problem is how to force an applet to load file from server but not from cache.
I posted the code for making an URLConnection to the file on the server and download it.
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 25 total points
Comment Utility
Oh yes - so I see now (this thread has got quite long ;-)). DataInputStream would not be necessary, but in any case, that could be the following I think:

try
{
     url = new URL("http", "serverURL", "fileName");
     URLConnection con = (URLConnection) url.openConnection();
     con.setUseCaches(false);
     BufferedImage img = javax.imageio.ImageIO.read(con.getInputStream());
} catch (Exception e)
{
     e.printStackTrace();
}
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Thanks for your comment
I will try that

Narayanaswamy
0
 

Author Comment

by:Narayanaswamy
Comment Utility
Thanks Experts...
It worked for me

The coding I used in the applet is...
public void update(Graphics g){
      paint(g);
}
public void paint(Graphics g){
      i= (i+1)%4;
      URL url;
  try
{
     url = new URL(getCodeBase(),fileNames[i]);
     URLConnection con = (URLConnection) url.openConnection();
     con.setUseCaches(false);
     BufferedImage img = javax.imageio.ImageIO.read(con.getInputStream());
       g.drawImage(img,0,0,this);
} catch (Exception e)
{
     e.printStackTrace();
}


and in the Painting thread

                  while(isRunning){
                ImgApplet.this.repaint();
                        try{Thread.sleep(500); }catch(Exception e){}
                  }

But some times it shows the Index out of bounds Exception.... In the applet.

Thanks once again
Narayanaswamy
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now