skippy
May 6th, 2000, 06:42 AM
Hi !
I have a canvas-derived class used in an applet.
I have declared a variable global to this class:
public
class LView1
extends Canvas
{
private int[][] laby = new int[75][75];
private int labSize;
private Image screenImageBuffer;
private Graphics screen;
private Image[] stoneImageBuffer = new Image[stoneCount];
....
In the constructor, I define this Array:
public
LView1()
{
super();
this.setSize(300,300);
for (int i=0;i<30;i++)
{
for (int j=0;j<30;j++)
{
laby[i][j] = 1;
}
}
this.repaint();
}
When I try to access any index of this Array, at this point everythings ok.
But later, in another procedure, I get an
ArrayIndexOutOfBoundsException,
as soon as i or j become larger than 29.
public
boolean updateView()
{
screenImageBuffer = createImage(300,300);
screen = screenImageBuffer.getGraphics();
for (int i=0;i<labSize;i++)
{
for (int j=0;j<labSize;j++)
{
drawSingleStone:{
for (int playerNr=0;playerNr<4;playerNr++)
{
if ((i == player[playerNr].x)&&(j == player[playerNr].y))
{
screen.drawImage(stoneImageBuffer[11+playerNr],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
break drawSingleStone;
}
}
screen.drawImage(stoneImageBuffer[laby[i][j]],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
}
}
}
this.repaint();
return true;
}
}
Any suggestions?
cu
Skippy
I have a canvas-derived class used in an applet.
I have declared a variable global to this class:
public
class LView1
extends Canvas
{
private int[][] laby = new int[75][75];
private int labSize;
private Image screenImageBuffer;
private Graphics screen;
private Image[] stoneImageBuffer = new Image[stoneCount];
....
In the constructor, I define this Array:
public
LView1()
{
super();
this.setSize(300,300);
for (int i=0;i<30;i++)
{
for (int j=0;j<30;j++)
{
laby[i][j] = 1;
}
}
this.repaint();
}
When I try to access any index of this Array, at this point everythings ok.
But later, in another procedure, I get an
ArrayIndexOutOfBoundsException,
as soon as i or j become larger than 29.
public
boolean updateView()
{
screenImageBuffer = createImage(300,300);
screen = screenImageBuffer.getGraphics();
for (int i=0;i<labSize;i++)
{
for (int j=0;j<labSize;j++)
{
drawSingleStone:{
for (int playerNr=0;playerNr<4;playerNr++)
{
if ((i == player[playerNr].x)&&(j == player[playerNr].y))
{
screen.drawImage(stoneImageBuffer[11+playerNr],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
break drawSingleStone;
}
}
screen.drawImage(stoneImageBuffer[laby[i][j]],i*stoneSize,j*stoneSize,stoneSize,stoneSize,this);
}
}
}
this.repaint();
return true;
}
}
Any suggestions?
cu
Skippy