www.pudn.com > 50code.rar > Pictures.java, change:2007-02-26,size:2148b

```package demo;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class Pictures {
private int m_nX;				//图像左上角的X坐标
private int m_nY;				//图像左上角的Y坐标
//定义两个个数组，分别不同点的X与Y坐标
private int m_aDefferX[] = { 73, 70, 54, 57, 30 };
private int m_aDefferY[] = { 12, 58, 81, 91, 115 };

//定义数组，标识不同点是否被发现
private boolean m_bFind[] =
{false, false, false, false, false};

private Image m_PictureImg;	//存储两幅相似的图像

public Pictures( int scrWidth, int scrHeight ){
try{
m_PictureImg = Image.createImage("/demo/dog.png");
m_nX = scrWidth/2 - m_PictureImg.getWidth()/2;
m_nY = scrHeight/2 - m_PictureImg.getHeight()/2;
}
catch (Exception ex){}
}

//获取不同点的个数
public int getDiffNum(){
return m_bFind.length;
}

//返回已找到的不同点的数量
public int getFindNum(){
int num = 0;
for( int n = 0; n < m_bFind.length; n ++ ){
if( m_bFind[n] == true )
num ++;
}
return num;
}

//判断某处是否有不同点
public void CheckDiffer( int x, int y ){
int lx = m_nX;
int rx = m_nX + 80;
for( int n = 0; n < m_bFind.length; n ++ ){
//判断左边的图像
if( x >= lx + m_aDefferX[n] - 10 &&
x <= lx + m_aDefferX[n] + 10 &&
y >= m_nY + m_aDefferY[n] - 10 &&
y <= m_nY + m_aDefferY[n] + 10 ){
m_bFind[n] = true;
break;
}
//判断右边的图像
if( x >= rx + m_aDefferX[n] - 10 &&
x <= rx + m_aDefferX[n] + 10 &&
y >= m_nY + m_aDefferY[n] - 10 &&
y <= m_nY + m_aDefferY[n] + 10 ){
m_bFind[n] = true;
break;
}
}
}
//显示两幅相似的图像，以及已找到的不同之处
public void Paint( Graphics g ){
g.drawImage(m_PictureImg, m_nX, m_nY, 0);
//在已找出的不同点上画标记
for( int n = 0; n < m_bFind.length; n ++ ){
if( m_bFind[n] == true ){
//在左边图像上画标记
g.drawArc( m_nX + m_aDefferX[n] - 10,
m_nY + m_aDefferY[n] - 10, 20, 20, 0, 360 );
//在右边图像上画标记
g.drawArc( m_nX + m_aDefferX[n] + 80 - 10,
m_nY + m_aDefferY[n] - 10, 20, 20, 0, 360  );
}
}
}
}
```