100分求助拼图如何显示在模拟器正中央,帮忙修改代码
MainCanvas代码如下:
import java.util.Random;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
public class MainCanvas extends Canvas implements Runnable,CommandListener{
public Image m_aImg[];
public int m_anCur[][];
public int m_nHidX, m_nHidY;
public int m_nSta;
private Command ExitCommand;
private PuzzleMidlet midlet;
public MainCanvas( PuzzleMidlet mMidlet )
{
midlet = mMidlet;
try
{
ExitCommand = new Command( "Exit ", Command.EXIT, 0);
addCommand(ExitCommand);
setCommandListener(this);
m_nHidX = 2;
m_nHidY = 2;
m_nSta = 0;
InitCurrent();
m_aImg = new Image[9];
StringBuffer temp = null;
for( int i = 0; i < 9; i ++ )
{
temp=new StringBuffer();
temp.append( "/pic ");
temp.append(i);
temp.append( ".png ");
m_aImg[i] = Image.createImage(temp.toString());
temp=null;
}
}
catch (Exception ex)
{//暂不做出错处理
}
Thread thread = new Thread(this);
thread.start();
}
public void InitCurrent()
{
Random random = new Random();
m_anCur = new int[][] { {0,1,2}, {3,4,5}, {6,7,8} };
int Rx, Ry, k, nTemp;
for( int x = 0; x < 3; x ++ )
{
for( int y = 0; y < 3; y ++ )
{
k = random.nextInt();
Rx = Math.abs(k % 3);
k = random.nextInt();
Ry = Math.abs(k % 3);
if( Rx != x || Ry != y )
{
nTemp = m_anCur[y][x];
m_anCur[y][x] = m_anCur[Ry][Rx];
m_anCur[Ry][Rx] = nTemp;
}
}
}
}
protected void paint(Graphics g)
{
g.setColor(0);
g.fillRect( 0, 0, getWidth(), getHeight() );
int nImg = 0; //暂存图片的编号
switch( m_nSta )
{
case 0:
for( int x = 0; x < 3; x++ )
{
for( int y = 0; y < 3; y++ )
{