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

📄 figure.java

📁 java实现的版画图程序
💻 JAVA
字号:
package drawfigure;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author unascribed * @version 1.0 */import java.awt.*;import java.awt.geom.*;public abstract class Figure {	private Point2D startPoint = null;	private Point2D endPoint = null;	private boolean isFirstDraw = true; //是否第一次画	private boolean isSelected = false;	private boolean isMoving = false;	private boolean isResizing = false;	private boolean isDrawing = false;	/**	 * 固定点,resize时使用	 */	private int activePosi;	public Point2D getStartPoint() {		return startPoint;	}	public void setStartPoint(Point2D p) {		//anchor=p;		startPoint = p;	}	public Point2D getEndPoint() {		return endPoint;	}	public void setEndPoint(Point2D p) {		endPoint = p;	}	public boolean isFirstDraw() {		return isFirstDraw;	}	public void setFirstDraw(boolean b) {		isFirstDraw = b;	}	public boolean isSelected() {		return isSelected;	}	public void selected() {		isSelected = true;	}	public void unSelected() {		isSelected = false;	}	public boolean isMoving() {		return isMoving;	}	public void setMoving(boolean b) {		isMoving = b;	}	public boolean isResizing() {		return isResizing;	}	/**	 * @param b	 */	public void setResizing(boolean b) {		isResizing = b;	}	public void setResizing(boolean b, int posi) {		setResizing(b);		setActivePosition(posi);	}	public boolean isDrawing() {		return isDrawing;	}	public void setDrawing(boolean b) {		isDrawing = b;	}	public int getActivePosition() {		return activePosi;	}	public void setActivePosition(int posi) {		activePosi = posi;	}	public void setStartEndPoint(Point2D start, Point2D end) {		this.setStartPoint(start);		this.setEndPoint(end);	}	public Figure() {	};	public Figure(Point2D p) {		this.setEndPoint((Point2D) p.clone());		this.setStartPoint((Point2D) p.clone());	}	//抽象方法	/**	 * 判断点p是否在本图形的区域内	 */	public abstract boolean pointInside(Point2D p);	/**	 * 返回当前鼠标位置所在的控制块,	 * 如果不在任何控制块内,返回null	 */	public abstract boolean pointInControlRect(Point2D p);	public abstract ControlRect getControlRect(Point2D p);	/**	 * 同pointInResizeControl(Point2D p);	 * @param p	 * @return	 */	/**	 * 根据点坐标在哪个选择块中,得到改变大小的光标类型 	 */	public Cursor getCursor(Point2D p) {		ControlRect ctrl = this.getControlRect(p);		if (ctrl != null) {			return ctrl.getCursor();		}		return new Cursor(Cursor.DEFAULT_CURSOR);	}	/**	 * 画图	 * @param g	 */	public abstract void draw(Graphics g);	/**	 * 返回边界	 * @return	 */	public Rectangle2D getBounds() {		double x, y, width, height;		x = Math.min(getStartPoint().getX(), getEndPoint().getX());		y = Math.min(getStartPoint().getY(), getEndPoint().getY());		width = Math.abs(getStartPoint().getX() - getEndPoint().getX());		height = Math.abs(getStartPoint().getY() - getEndPoint().getY());		return new Rectangle2D.Double(x, y, width, height);	}	/**	* 移动,使用之前,需要先g.setXORMode(Color);	* 似乎有点不妥!!===	*/	public void move(Graphics g, double offsetX, double offsetY) {		if (isMoving()) {			draw(g);		}		setStartEndPoint(			new Point2D.Double(				getStartPoint().getX() + offsetX,				getStartPoint().getY() + offsetY),			new Point2D.Double(				getEndPoint().getX() + offsetX,				getEndPoint().getY() + offsetY));		draw(g);		setMoving(true);	}	/**		* 移动,使用之前,需要先g.setXORMode(Color);		* 似乎有点不妥!!===		* 不同的图形,实现不同,放到子类实现		*/	public void resize(Graphics g, double offsetX, double offsetY) {		if (isResizing()) {			draw(g);		}		Rectangle2D bound = getBounds();		switch (getActivePosition()) {			case ControlRect.LEFT_TOP_POSITION : //左上				setStartPoint(					new Point2D.Double(						bound.getX() + offsetX,						bound.getY() + offsetY));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth(),						bound.getY() + bound.getHeight()));				break;			case ControlRect.TOP_POSITION : //上				setStartPoint(					new Point2D.Double(						bound.getX(),						bound.getY() + bound.getHeight()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth(),						bound.getY() + offsetY));				break;			case ControlRect.RIGHT_TOP_POSITION : //右上				setStartPoint(					new Point2D.Double(						bound.getX(),						bound.getY() + bound.getHeight()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth() + offsetX,						bound.getY() + offsetY));				break;			case ControlRect.RIGHT_POSITION : //右				setStartPoint(new Point2D.Double(bound.getX(), bound.getY()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth() + offsetX,						bound.getY() + bound.getHeight()));				break;			case ControlRect.RIGHT_BOTTOM_POSITION : //右下角				setStartPoint(new Point2D.Double(bound.getX(), bound.getY()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth() + offsetX,						bound.getY() + bound.getHeight() + offsetY));				break;			case ControlRect.BOTTOM_POSITION : //下				setStartPoint(new Point2D.Double(bound.getX(), bound.getY()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth(),						bound.getY() + bound.getHeight() + offsetY));				break;			case ControlRect.LEFT_BOTTOM_POSITION : //左下				setStartPoint(					new Point2D.Double(						bound.getX() + offsetX,						bound.getY() + bound.getHeight() + offsetY));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth(),						bound.getY() + bound.getHeight()));				break;			case ControlRect.LEFT_POSITION : //左				setStartPoint(					new Point2D.Double(bound.getX() + offsetX, bound.getY()));				setEndPoint(					new Point2D.Double(						bound.getX() + bound.getWidth(),						bound.getY() + bound.getHeight()));				break;		}		draw(g);		setResizing(true, getActivePosition());	}}

⌨️ 快捷键说明

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