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

📄 moveaction.java

📁 一个简易的java画图软件
💻 JAVA
字号:
package app.action;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

import draw.PaintCanvas;
import draw.View;

/**
 * 移动图形的Action,主要用于键盘的控制
 * 
 * @author Thihy
 * 
 */
public abstract class MoveAction extends AbstractAction {
	protected int dx, dy;
	protected View view;

	public MoveAction(View view, int dx, int dy) {
		super();
		this.view = view;
		this.dx = dx;
		this.dy = dy;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		try {
			PaintCanvas gbc = view.getCanvas();
			gbc.translateCurrentFiguare(dx, dy);
		} catch (NullPointerException evt) {
			// 啥也不做
		}
	}

	/**
	 * 向东移动一个像素
	 * 
	 * @author Thihy
	 * 
	 */

	public static class East extends MoveAction {
		public final static String ID = "moveEast";

		public East(View view) {
			super(view, 1, 0);

		}
	}

	/**
	 * 向西移动一个像素
	 * 
	 * @author Thihy
	 * 
	 */
	public static class West extends MoveAction {
		public final static String ID = "moveWest";

		public West(View view) {
			super(view, -1, 0);
		}
	}

	/**
	 * 向北移动一个像素
	 * 
	 * @author Thihy
	 * 
	 */
	public static class North extends MoveAction {
		public final static String ID = "moveNorth";

		public North(View view) {
			super(view, 0, -1);
		}
	}

	/**
	 * 向南移动一个像素
	 * 
	 * @author Thihy
	 * 
	 */
	public static class South extends MoveAction {
		public final static String ID = "moveSouth";

		public South(View view) {
			super(view, 0, 1);
		}
	}
}

⌨️ 快捷键说明

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