this is a code that i found fromsome website
I replaced line 18 by this line below, and put theimage ho.gif in the project folder. Sth is wrong..image is not displayed on the screen? what is the problem??
I jsut wanted to try it using one image only............that's why i just put the same image in the for loop.
these are the lines i replaced line 18 with.

{
Toolkit toolkit = Toolkit.getDefaultToolkit();
picture[i] = toolkit.getImage("ho.gif");
}


import java.awt.*;
 2:
 3: public class Animate extends javax.swing.JApplet
 4:   implements Runnable {
 5:
 6:   Image[] picture = new Image[6];
 7:   int totalPictures = 0;
 8:   int current = 0;
 9:   Thread runner;
10:   int pause = 500;
11:
12:   public void init() {
13:     for (int i = 0; i < 6; i++) {
14:       String imageText = null;
15:       imageText = getParameter("image"+i);
16:       if (imageText != null) {
17:         totalPictures++;
18:         picture[i] = getImage(getCodeBase(), imageText);
19:       } else
20:         break;
21:     }
22:     String pauseText = null;
23:     pauseText = getParameter("pause");
24:     if (pauseText != null) {
25:       pause = Integer.parseInt(pauseText);
26:     }
27:   }
28:
29:   public void paint(Graphics screen) {
30:     super.paint(screen);
31:     Graphics2D screen2D = (Graphics2D) screen;
32:     if (picture[current] != null)
33:       screen2D.drawImage(picture[current], 0, 0, this);
34:   }
35:
36:   public void start() {
37:     if (runner == null) {
38:       runner = new Thread(this);
39:       runner.start();
40:     }
41:   }
42:
43:   public void run() {
44:     Thread thisThread = Thread.currentThread();
45:     while (runner == thisThread) {
46:       repaint();
47:       current++;
48:       if (current >= totalPictures)
49:         current = 0;
50:       try {
51:         Thread.sleep(pause);
52:       } catch (InterruptedException e) { }
53:     }
54:   }
55:
56:   public void stop() {
57:     if (runner != null) {
58:       runner = null;
59:     }
60:   }
61: }
14:       String imageText = null;
15:       imageText = getParameter("image"+i);
16:       if (imageText != null) {

The next line will only run if imageText is not null, so your call to getParameter method must return something. I would suggest putting in a println statement to see what the value of imageText is immediately before the if-statement. Just don't forget to remove the println afterwards!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.