Canvas类 低级界面开发的一个初步程序
package DrawSin;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class MIDlet1 extends MIDlet
{
private Display dis;
private Draw d = new Draw();
protected void startApp() throws MIDletStateChangeException
{
d.setTitle("DrawSin");
dis = Display.getDisplay(this);
dis.setCurrent(d);
}
class Draw extends Canvas
{
protected void paint(Graphics g)
{
g.setColor(255, 0, 0);
g.drawLine(0, 150, 300, 150);//x轴
g.drawLine(100, 0, 100, 300);//y轴
int y=0;
for(int x=0;x<=3600;x++)
{
y= (int)(150+10*Math.sin(x*Math.PI/180));
g.drawLine((int)(x/10), y, (int)(x/10), y);
}
}
}
protected void destroyApp(boolean unconditional)
throws MIDletStateChangeException
{
}
protected void pauseApp()
{
}
}
posted on 2008-07-19 23:20
atskyline 阅读(497)
评论(0) 编辑 收藏 引用 所属分类:
J2ME笔记