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

📄 sketcharea.java

📁 FIRE (Flexible Interface Rendering Engine)是一个J2ME上的灵活的图形界面引擎
💻 JAVA
字号:
/** *  */package gr.fire.ui;import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;import gr.fire.core.Component;import gr.fire.core.FireScreen;/** * @author padeler * */public class SketchArea extends Component {		private Image area;	private int POINT_BUF_LENGTH=18; // number of points in buffer	private int[] pointBuf = new int[POINT_BUF_LENGTH*2]; 	private int pointsPointer=0;		private void add(int x,int y)	{		if(pointsPointer==POINT_BUF_LENGTH)		{			flush();		}		pointBuf[pointsPointer*2] = x;		pointBuf[pointsPointer*2 +1 ] = y;		pointsPointer++;	}		public void validate()	{		int[]ps = getPrefSize();		if(ps==null) ps = getMinSize();		if(width<=0 || height<=0)		{			width = ps[0];			height = ps[1];		}		area = Image.createImage(width,height);		clear();		valid=true;			}		public int[] getMinSize()	{		FireScreen fs = FireScreen.getScreen();		return new int[]{fs.getWidth(),fs.getHeight()};	}		public void clear()	{		Graphics g = area.getGraphics();				g.setColor(backgroundColor);		g.fillRect(0,0,width,height);		pointsPointer=0;		repaint();	}		public Image getSketch()	{		return area;	}			public void paint(Graphics g)	{		g.drawImage(area,0,0,Graphics.TOP|Graphics.LEFT);	}		public boolean isFocusable()	{		return true;	}		protected void keyReleased(int keyCode)	{		setSelected(!isSelected());	}		protected void pointerDragged(int x, int y)	{		pointerEvent(x,y);	}		protected void pointerReleased(int x, int y)	{		flush();		pointerEvent(x,y);	}		protected void pointerPressed(int x, int y)	{		flush();		pointerEvent(x,y);	}		private void flush()	{			if(pointsPointer>=2) // at least two points		{			Graphics g = area.getGraphics();			g.setColor(foregroundColor);			for(int i=0;i<pointsPointer-2;i++)			{				g.drawLine(pointBuf[i*2],pointBuf[i*2+1],pointBuf[i*2+2],pointBuf[i*2+3]);				g.drawLine(pointBuf[i*2]+1,pointBuf[i*2+1],pointBuf[i*2+2]+1,pointBuf[i*2+3]);			}			repaint();			}		pointsPointer=0;	}		protected void pointerEvent(int x, int y)	{		if(isDublicate(x,y)==false)		{			add(x,y);		}	}		private boolean isDublicate(int x,int y)	{		if(pointsPointer>0 && pointBuf[(pointsPointer-1)*2]==x && pointBuf[(pointsPointer-1)*2+1]==y)		{			return true;		}		return false;	}}

⌨️ 快捷键说明

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