Thread(ThreadGroup group,Runable target,String name) |
final int XCELLS=5; //每行拼图的数? final int YCELLS=4;//每列拼图的数? final int ALLCELLS=20;//分割元素的数? final int EMPTY=19;//第20单元Q即cellsQ?9Q置? //I白囑փ |
class Cell {int sx,sy; //起始位置 int cx,cy; //当前位置 Image img; //单元囑փ public Cell(Image img,int x,int y) //CellcL造函? {this.img=img; sx=x;sy=y;} //lv始位|赋gؓx,y } |
MediaTracker tracker=new MediaTracker(this) //为当前用类建立1个MediaTracker实体Q用于跟t类 //上的囑փ cellsQEMPTYQ?new Cell(createEmpty(),toPoint(EMPTY).x,toPoint(EMPTY).y); tracker.addImage(cellsQEMPTYQ?img,0); //调用createEmpty()Ҏ产生I白囑փQƈ加入到所跟踪 //的cells数组?0单元 void setPosition(int x,int y) //讄单元囑փ当前位置 {cx=x;cy=y;} |
int positionQ]Q]=new intQXCELLsQEYCELLSQ? |
Thread imageThread=null; //定义U程imageThread,初始 //gؓI? public void run() {imageThread.setPriority(Thread.MINPRIORITY);//讄U? //E执行优先? try {imageThread.sleep(2000);//U程睡眠{待2000ms }catch(InterruptedException e){} first=changeArray();//调用changeArray()Ҏ随机改变? //像单元位|? while(!loaded)//判断囑փ若未被跟t蝲入,则调用相? //Ҏ跟踪q加载图? {repaint(); try {imageThread.sleep(100); }catch(InterruptedException e){System.out.println(e);} } } |
boolean changeArray() { int sourceQ]=new intQ?0Q? int fullQ]=new intQ?0Q? for(int i=0;i<ALLCELLS;i++) { int r=(int)(Math.random()*20); while(fullQrQ?=0) r=(r+(int)(Math.random()*20))%20; sourceQiQ?r; fullQrQ?1; } int pos=0; for(int i=0;i<ALLCELLS;i++,pos++) { Point p=toPoint(sourceQposQ?; cellsQposQ?setPosition(p.x,p.y); positionQp.xQEp.yQ?pos; } x=cellsQEMPTYQ?cx; y=cellsQEMPTYQ?cy; return(false); } |
Image crop(int pos) {//pos参数用函数给出的囑փ单元位置? Point p=toPoint(pos);//位|号转化为坐标Ş? ImageFilter filter=new CropImageFilter(xside*p.x,yside*p.y,xside,yside); //在给定坐标和长宽的绝对矩形区域内创徏分割囑փq? //滤器实体filter ImageProducer producer=new FilteredImageSource(baseImage.getSource(),filter;) //由原囑փ和分割图像过滤器实体创徏新的囑փ //产生器producer return createImage(producer);//由图像生器producer产生 //囑փq返? } |
可是Q如果通过了多U反向代理的话,X-Forwarded-For的值ƈ不止一个,而是一Ԍp|I竟哪个才是真正的用L的真实IP呢?
{案是取X-Forwarded-For中第一个非unknown的有效IP字符丌Ӏ?br />
如:
X-Forwarded-ForQ?92.168.1.110, 192.168.1.120, 192.168.1.130, 192.168.1.100
用户真实IP为: 192.168.1.110
public String getIpAddr(HttpServletRequest request) {
2 String ip = request.getHeader("x-forwarded-for");
3 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
4 ip = request.getHeader("Proxy-Client-IP");
5 }
6 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
7 ip = request.getHeader("WL-Proxy-Client-IP");
8 }
9 if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
10 ip = request.getRemoteAddr();
11 }
12 return ip;
13 }