📄 drawgraphics.java
字号:
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class DrawGraphics extends MIDlet implements CommandListener {
Display display;
//画布
GraphicCanvas gc;
//画线
Command cmdLine = new Command("Line", Command.SCREEN, 1);
//画没有填充的矩形
Command cmdRect = new Command("Rectangle", Command.SCREEN, 1);
//画没有填充的圆角矩形
Command cmdRoundRect = new Command("Round Rectangle", Command.SCREEN, 1);
//画没有填充的弧线
Command cmdArc = new Command("Arc", Command.SCREEN, 1);
//画有填充的矩形
Command cmdFillRect = new Command("Fill Rectangle", Command.SCREEN, 1);
//画有填充的圆角矩形
Command cmdFillRoundRect = new Command("Fill Round Rectangle", Command.SCREEN, 1);
//画有填充的弧线
Command cmdFillArc = new Command("Fill Arc", Command.SCREEN, 1);
//画有填充的弧线
Command cmdFillTriangle = new Command("Fill Triangle", Command.SCREEN, 1);
public DrawGraphics() {
super();
//创建画布对象实例
gc = new GraphicCanvas();
gc.addCommand(cmdLine);
gc.addCommand(cmdRect);
gc.addCommand(cmdRoundRect);
gc.addCommand(cmdArc);
gc.addCommand(cmdFillRect);
gc.addCommand(cmdFillRoundRect);
gc.addCommand(cmdFillArc);
gc.addCommand(cmdFillTriangle);
gc.setCommandListener(this);
}
protected void startApp() throws MIDletStateChangeException {
//获得当前MIDlet的Display对象
display = Display.getDisplay(this);
//设置GraphicCanvas对象为当前显示对象
display.setCurrent(gc);
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0)
throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
/**
* 处理命令按钮事件
*/
public void commandAction(Command c, Displayable d) {
if (c == this.cmdLine) {
gc.draw(GraphicCanvas.LINE);
} else if (c == cmdRect) {
gc.draw(GraphicCanvas.RECTANGL_NO_FILL);
} else if (c == cmdRoundRect) {
gc.draw(GraphicCanvas.ROUNDRECTANGLE_NO_FILL);
} else if (c == cmdArc) {
gc.draw(GraphicCanvas.ARC_NO_FILL);
} else if (c == cmdFillRect) {
gc.draw(GraphicCanvas.RECTANGL_FILL);
} else if (c == cmdFillRoundRect) {
gc.draw(GraphicCanvas.ROUNDRECTANGLE_FILL);
} else if (c == cmdFillArc) {
gc.draw(GraphicCanvas.ARC_FILL);
} else if (c == cmdFillTriangle) {
gc.draw(GraphicCanvas.TRIANGLE_FILL);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -