public void finishRect(int x, int y){	selectionflag = true;
		if(x<0){x = 0;} if(y<0){y=0;}if(x>xdim-1){x = xdim-1;} if(y>ydim-1){y = ydim-1;} 
		if(rectx > x){rectxc = rectx; rectxb = x;}else{rectxc = x; rectxb = rectx;}
		if(recty > y){rectyc = recty; rectyb = y;}else{rectyc = y; rectyb = recty;}
		for (int a = rectyb; a <= rectyc; a++){
			for(int b = rectxb; b <= rectxc; b++){
				setSelection(b,a,rectstateb); }}
		 repaint();}