⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 restorablekeyaction.java

📁 Java版拼图游戏
💻 JAVA
字号:
/*
 * @(#)RestorableKeyAction.java 1.0 03/08/22
 * Copyright 2003 Entao Zhang, All rights reserved.
 */

import javax.swing.*;
import java.awt.event.ActionEvent;

/**
 * 拼图一般方式的专用键盘事件处理类.用于键盘方向键操作.
 */
public class RestorableKeyAction extends AbstractAction {
	private ImageRevertUnitPane ir;
	private int x,step,temp;
	private int loc,swap;
	private int swapX,swapY;
	private int grids[];
	public RestorableKeyAction(ImageRevertUnitPane ir,String way){
		this.ir=ir;
		if(way=="LEFT") step=1;
		else if(way=="RIGHT") step=-1;
		else if(way=="UP") step=2;
		else if(way=="DOWN") step=-2;
	}
   	public void actionPerformed(ActionEvent e) {
		if (ir.isConfused()){
			x=ir.x; swap=ir.swap;
			grids=ir.grids;
			
			swapX=swap%x; swapY=swap/x;
			loc=swap+(step==2?x:(step==-2?-x:step));
			if ((step==-1 && swapX==0) || (step==1 && swapX==(x-1)) ||
				(step==-2 && swapY==0) || (step==2 && swapY==(ir.y-1))){
				return;
			}
			ir.cm.swapStateChange(true);
			temp=grids[swap];
			grids[swap]=grids[loc];
			ir.cm.componentStateChange(swap);
			grids[loc]=temp;
			ir.swap=loc;
			ir.cm.swapStateChange(false);
			ir.isDone();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -