首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

java.lang.ArrayIndexOutOfBoundsException解决方法!

2014-01-26 
//import java.lang.* import javax.microedition.lcdui.* //import java.util.Random //import javax.m

//import java.lang.*;
import javax.microedition.lcdui.*;
//import java.util.Random;
//import javax.microedition.rms.*;
//import java.io.*;
//import MainMid;
//import MainPit.*;
//import com.*;
class MyCanvas extends Canvas implements Runnable
{
MyMIDlet myMid;
// 按键表
// private static final byte KEY_NONE = 0;
private static final byte KEY_UP = -1;
private static final byte KEY_DOWN = -2;
private static final byte KEY_LEFT = -3;
private static final byte KEY_RIGHT = -4;
private static final byte KEY_FIRE = -5;
private static final byte KEY_GAM_LEFT = -6;
private static final byte KEY_GAM_RIGHT = -7;
private static final byte KEY_NUM5 = 53;
private int hangfire = 300;// 延时大小
Graphics gb;
private Image bufImg;// 缓存
// 屏幕大小
private int nWidth;
private int nHeight;
/**
* 构造方法
* @param mid
*/
public MyCanvas(MyMIDlet mid)
{
myMid = mid;
nWidth = getWidth();// 屏幕大小
nHeight = getHeight();
cw = nWidth / 10;//把屏幕分成 10*10 的小格子
ch = nHeight / 10;
try
{
bufImg = Image.createImage(nWidth, nHeight);// 申请缓存空间
gb = bufImg.getGraphics();
} catch (Exception e)
{
System.out.println( "构造方法 ");
e.printStackTrace();
}
}
/**
* 刷新屏幕
* @param c
*/
private void clearScreen(int c)// 用颜色c刷新屏幕
{
gb.setColor(c);
gb.fillRect(0, 0, nWidth, nHeight);
}
/**
* 画笔
*/
public void paint(Graphics g){gb = g;}
private int cx, cy;//鼠标按下的时候 所在的起始点小方格的 行和列
/**
* 显示鼠标位置
*/
private void showCursor()
{
gb.setColor(0x000000ff);
gb.drawRect(cx * cw + 2, cy * ch + 2, cw - 4, ch - 4);
}
/**
* 按下起始位置
*
*/
private void showBegin()
{
gb.setColor(0x0000ff00);
gb.fillArc(begin_x * cw, begin_y * ch, cw, ch, 0, 360);
}
private int cw, ch;//每一个小格子的宽度和高度
/**
* 显示初始界面
*
*/
private void showMap()
{
try{
clearScreen(0x00ffffff);//背景色
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
if (moveSpace[i][j] == 1)//索引是 1 则绘制线条 否则填充障碍物
{
gb.setColor(0x00000000);//线条颜色
gb.drawRect(j * cw, i * ch, cw, ch);
} else
{
gb.setColor(0x00000000);//障碍颜色
gb.fillRect(j * cw, i * ch, cw, ch);
}
}
}
}catch(Exception e)
{
System.out.println( "showMap() error ");
e.printStackTrace();
}
}
int state = 0;
public void run()
{
while (true)
{
try{System.out.println( "state= "+state);
switch (state)
{
case 0://初始界面
showMap();//地图信息
showCursor();//鼠标位置
break;
case 1://开始按下         

热点排行