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

📄 circlecanvas.java

📁 我想在J2ME上画个从中心向外扩展的圆
💻 JAVA
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class CircleCanvas extends Canvas implements Runnable{
	int px,py;//圆心位置
	int r;
	int scrWidth,scrHeight;
	int count;//次数
	CircleCanvas()
	{
		scrWidth=this.getWidth();
		scrHeight=this.getHeight();
		r=1;
		px=scrWidth/2-r/2;
		py=scrHeight/2-r/2;
		count=0;
	}
	protected void paint(Graphics g) {
		g.setColor(0xFF000000);
		g.fillRect(0, 0, scrWidth, scrHeight);
		drawCircle(g);
		
	}
	public void run() {
		while(true)
		{
			r+=2;
			if(count<1)
			{
				if(r>=80)
				{
					r=0;
					count++;
				}
			}else
			{
				if(r>=40)
				{
					r=0;
					count++;
				}
			}
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			repaint();
			
		}
		
	}
	
	void drawCircle(Graphics g)
	{
		g.setColor(0xC8BE7F);
		g.drawArc(px, py, r, r, 0, 180);
		g.drawArc(px, py, r, r, 180, 360);
		
	}
}

⌨️ 快捷键说明

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