• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

haveing trouble with applet animation plz help

 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all I have been trying to make an nice applet animation for our site but when i try to run it with the applet viewer, but it gives me an nullpointer exception, here is my code I hope someone can help me with this (I'm a new coder and this is my first animation applet so if there is something wrong with my code plz tell me)
import java.awt.Graphics.*;
import javax.swing.ImageIcon;
import javax.swing.*;
import java.net.*;
import java.awt.Image;

public class AtlanticFlameLogo extends JApplet implements Runnable
{
private URL logoFile;
private Image logo;
private Thread runner;
private Color bgColor = new Color(0,0,0);
private Graphics g;
private boolean threadSuspended;

public void init()
{
try
{
logoFile = new URL("C:\\applet\\lanparty\\ap");
}
catch(MalformedURLException e)
{ }
}/* End of public void init() */

public void start()
{
runner = new Thread(this);
runner.start();
}/* End of public void start() */

public void stop()
{
runner = null;
if (threadSuspended)
{
threadSuspended = false;
notify();
}
} /* End of public stop */



public void destroy()
{
logoFile = null;
logo = null;
bgColor = null;
System.gc();
}/* End of public void destroy */

public void run()
{
Thread runingT = Thread.currentThread();
while(runingT == runner);
try
{
for(int i = 1 ; i < 12 ; i++)
{
logo = getImage(logoFile ,"img"+i+".gif");
repaint();
Thread.sleep(10000);
}//end of for
}
catch(InterruptedException e)
{ }//end of catch
}//end of public void run


public void paint(Graphics g)
{
g.drawImage(logo, 0 ,0 ,this);
}// End of public void paint(Grahpics g)



}//end of applet
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hennie,
I think your problem is related to the way the getImage method works. It spawns a separate thread to read the image and returns to the calling method without actually having completed the load image task!
Use a MediaTracker object to find out when the image is actually loaded.

Regards,
Manfred.
 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks , it works now , if you want to have a look the address is
www.lantic.net/hompage/news/langame.htm
Originally posted by Manfred Leonhardt:
[B]Hi Hennie,
I think your problem is related to the way the getImage method works. It spawns a separate thread to read the image and returns to the calling method without actually having completed the load image task!
Use a MediaTracker object to find out when the image is actually loaded.

Regards,
Manfred.[/B]

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic