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

📄 rectangle.java

📁 画图程序
💻 JAVA
字号:
package LYD.Draw;

import java.awt.Graphics;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.Color;

public class Rectangle implements ITypeDrawCommand
{
	int x1=0;
	int y1=0;
	int x2=0;
	int y2=0;
	
	protected int brushType=0;
	protected Color _color=Color.BLACK;
	
	protected IBasicBrush _IBasicBrush=new Brush();
	
	public Rectangle(){}
	
	public Rectangle(Graphics g){_IBasicBrush.setGraphics(g);}
	
	
	public Rectangle(int _x1,int _y1,int _x2,int _y2,Color c,IBasicBrush i)
	{
		x1=_x1;
		y1=_y1;
		x2=_x2;
		y2=_y2;
		_color=c;
		_IBasicBrush.setColor(i.getColor());
		_IBasicBrush.setWidth(i.getWidth());
	}
	
	public void ReDo(Graphics g)
	{
		_IBasicBrush.setGraphics(g);
		if(x2<x1)
		{
			int t=x2;
			x2=x1;
			x1=t;
		}
		if(y2<y1)
		{
			int t=y2;
			y2=y1;
			y1=t;
		}
		_IBasicBrush.paintRectangle(x1,y1,x2-x1,y2-y1);
	}
	
	public void UnDo(){}
	
	public void setWidth(int w){_IBasicBrush.setWidth(w);}

	public Cursor getCursor(){return new Cursor(Cursor.DEFAULT_CURSOR);}
	
	public void setColor(Color color){_IBasicBrush.setColor(color);}
	
	public Color getColor(){return _IBasicBrush.getColor();}
	
	public void setGraphics(Graphics g){_IBasicBrush.setGraphics(g);}
	
	public void setType(int type)
	{
		if(type==0)
			this._IBasicBrush=new Brush();	
	}
	
	//the follow is the functions that handle the mouse events
	public void mouseReleased(MouseEvent e)
	{
		x2=e.getX();
		y2=e.getY();
		TypeDrawController.removeFromTop();
		TypeDrawController.addToTop(new LYD.Draw.Rectangle(x1,y1,x2,y2,Draw.foreColor,_IBasicBrush));
	}
	
	public void mousePressed(MouseEvent e)
	{
		x2=e.getX();
		y2=e.getY();
		x1=x2;
		y1=y2;
		TypeDrawController.addToTop(new LYD.Draw.Rectangle(x1,y1,x2,y2,Draw.foreColor,_IBasicBrush));
	}
	
	public void mouseExited(MouseEvent e)
	{
	}
	
	public void mouseEntered(MouseEvent e)
	{
	}
	
	public void mouseClicked(MouseEvent e)
	{
	}
	
	public void mouseMoved(MouseEvent e)
	{
	}
	
	public void mouseDragged(MouseEvent e)
	{
			x2=e.getX();
			y2=e.getY();
			TypeDrawController.removeFromTop();
			TypeDrawController.addToTop(new LYD.Draw.Rectangle(x1,y1,x2,y2,Draw.foreColor,_IBasicBrush));
	}
}

⌨️ 快捷键说明

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