0

I have a programm that runs an applet. It loads a series of images and paints them. The problem is the programm seems to not to paint the images in the same order..or rather it skips some of the images....what can i do?
I tried using the udate(screen) function but the screen bacame very flickerig. And also not all the images were painted..please help ..here is the code.The images are name image1.gif image2.gif etc

import java.awt.*;
 
  public class Animate extends javax.swing.JApplet
    implements Runnable {
 
   Image[] picture = new Image[7];
   int totalPictures = 0;
   int current = 0;
   Thread runner;
   int pause = 500;
   
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   public void init() {
     for (int i = 0; i <= 6; i++) {
       String imageText = null;
            totalPictures++;
          picture[i] = toolkit.getImage("image" + i + ".gif");
      
        }
     String pauseText = null;
     pauseText = getParameter("pause");
     if (pauseText != null) {
       pause = Integer.parseInt(pauseText);
     }
   }

   public void paint(Graphics screen) {
     super.paint(screen);
    Graphics2D screen2D = (Graphics2D) screen;
  Image myimage =  picture[current];
     if (picture[current] != null)
             screen2D.drawImage(picture[current], 0, 0, this);
  if (current == 6)
             update(screen2D);
  
      }
   public void start() {
     if (runner == null) {
       runner = new Thread(this);
       runner.start();
     }
   }

   public void run() {
     Thread thisThread = Thread.currentThread();
     while (runner == thisThread) {
       repaint();
        current++;
       if (current >= totalPictures)
         current = 0;
       try {
      //   Thread.sleep(pause);
           Thread.sleep(400);
       } catch (InterruptedException e) { }
     }
   }

   public void stop() {
     if (runner != null) {
       runner = null;
     }
   }
 }
2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Netztonia
0

Try to visit this site tutorialized.com.
It has everything you need to know about animation.
Try to use also or download Maya for animation, it's really good.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.