I'm stuck.
I'm trying to wirte a very small animation applet. It is suppose to import 15 BMPs and then of course play them back in an animation. I have the BMP's stored in a seperate directory but think I have the path right. It seems I am continually getting an "java.lang.ArrayIndexOutOfBoundsException: 15"
There are a lot of extra lines I have added to try and troubleshoot this but am not having any luck.
Any hel would be greatly appreciated.
package imageassignment;
/**
*
*/
import java.applet.Applet;
import java.awt.*;
import java.lang.Object;
public class Chapter21 extends Applet
{
private Image MC[];
private int totalImages = 15, // total number of images
currentImage = 0, // current image subscript
sleepTime = 10; // milliseconds to sleep
MediaTracker imageTracker; // load the images when the applet begins executing
Aframe myframe;
public void init()
{
//myframe=new Aframe(this);
//myframe.setVisible(true);
//System.out.println(getDocumentBase());
MC = new Image[ totalImages ];
imageTracker = new MediaTracker( this );
for ( int i = 0; i < MC.length; i++ )
{
MC[ i ] = getImage( getDocumentBase(),
"images/IMG" + (i+1) + ".bmp" );
imageTracker.addImage( MC[ i ], i );// track loading image
}
try
{
imageTracker.waitForID( 0 ); } catch( InterruptedException e ) { }
}
public void stop()
{
myframe.setVisible(false);
}
public void start(Graphics g)
{
//myframe.setVisible(true);
System.out.println("start");
g.drawImage(MC[0], 0,0, 300, 300,this);
currentImage = 1;
}
public void paint( Graphics g )
{
if ( imageTracker.checkID( currentImage, true ) )
{
System.out.println("paint");
g.fillRect(0,0,300,300);
// draw new image in buffer
for (int cntr=0; cntr<totalImages;cntr++)
{
g.drawImage(MC[ currentImage ], 0, 0, 300, 300, this );
currentImage = ++currentImage;
}
}
else
System.out.println("else");
postEvent( new Event( this, Event.MOUSE_ENTER, "" ) );
try
{
System.out.println("try");
Thread.sleep( sleepTime );
}
catch ( InterruptedException e )
{
System.out.println("catch");
showStatus( e.toString() );
}
repaint(); // display buffered image
}
// override update to eliminate flicker
public void update( Graphics g )
{
paint( g );
}
}