ScreenClick的用法

public class ScreenClick {

	public float x,y;
	public int I=-1,J=-1;
	public int priviousI=0,previousJ=0;
	public float xSpan,ySpan,xOffset,yOffset;
	
	public ScreenClick(float xSpan,float ySpan) {
		// TODO Auto-generated constructor stub
		this.xSpan=xSpan;
		this.ySpan=ySpan;
		this.xOffset=xSpan;
		this.yOffset=ySpan-10;
	}
	
	public void setCoor1(float x,float y){
		this.x=x;
		this.y=y;
		judge1();
	}
	
	public void setCoor2(float x,float y){
		this.x=x;
		this.y=y;
		judge2();
	}
	
	public void judge1(){
		
		label1 :for(int i=0;i<10;i++){
			for(int j=0;j<13;j++){
					if(i%2==0){
						if(isInRect_ou(i,j)){
							SV_main.x1=i;SV_main.y1=j;
							if(priviousI==i&&previousJ==j){
								SV_main.count=1;
							}else {
								SV_main.count=0;
								if(SV_main.colorEdgeFlag1){
									SV_main.x1=priviousI;SV_main.y1=previousJ;
									 SV_main.saveIndex[1]=getPreviousElementIndex();
								}
							}
						    I=i;J=j;
						    priviousI=i;previousJ=j;
						   
							break label1;
						}
					}else {
						if(isInRect_ji(i,j)){
							SV_main.x1=i;SV_main.y1=j;
							if(priviousI==i&&previousJ==j){
								SV_main.count=1;
							}else {
								SV_main.count=0;
								if(SV_main.colorEdgeFlag1){
									SV_main.x1=priviousI;SV_main.y1=previousJ;
									 SV_main.saveIndex[1]=getPreviousElementIndex();
								}
							}
							 I=i;J=j;
							  priviousI=i;previousJ=j;
							break label1;
						}
					}
				}
				
			}
		
	}
	
public void judge2(){
		
		label1 :for(int i=0;i<10;i++){
			for(int j=0;j<13;j++){
				if(i%2==0){
					if(isInRect_ou(i,j)){
						SV_main.x2=i;SV_main.y2=j;
						 I=i;J=j;
						break label1;
					}
				}else {
					if(isInRect_ji(i,j)){
						SV_main.x2=i;SV_main.y2=j;
						 I=i;J=j;
						break label1;
					}
				}
			}
		}
	}

	private boolean isInRect_ou(int i,int j) {
		// TODO Auto-generated method stub
		if(xSpan*j+xOffset+50<x&&x<xSpan*(j+1)+50+xOffset&&ySpan*i+yOffset<y&&y<ySpan*(i+1)+yOffset){
			return true;
		}
		return false;
	}
	
	private boolean isInRect_ji(int i,int j) {
		// TODO Auto-generated method stub
		if(xSpan*j+xOffset*0.5f+50<x&&x<xSpan*(j+1)+xOffset*0.5f+50&&ySpan*i+yOffset<y&&y<ySpan*(i+1)+yOffset){
			return true;
		}
		return false;
	}

	public float getX(){
		return x;
	}
	
	public float getY(){
		return y;
	}
	
	public int getI(){
		return I;
	}
	
	public int getJ(){
		return J;
	}
	
	public int getElementIndex(){
		//点击按钮输出对应的坐标,system。out
		if(I==3&&J==10){
			return 0;//na
		}
		if(I==2&&J==1){
			return 1;//cl
		}
		if(I==7&&J==5){
			return 2;//h
		}
		if(I==6&&J==5){
			return 3;//o
		}
		return 0;
	}
	
	public int getPreviousElementIndex(){
		//点击按钮输出对应的坐标,system。out
		if(priviousI==3&&previousJ==10){
			return 0;//na
		}
		if(priviousI==2&&previousJ==1){
			return 1;//cl
		}
		if(priviousI==7&&previousJ==5){
			return 2;//h
		}
		if(priviousI==6&&previousJ==5){
			return 3;//o
		}
		return 0;
	}
	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值