fullcanvas.java

来自「Java ME手机应用开发大全一书的配套光盘上的源码」· Java 代码 · 共 56 行

JAVA
56
字号
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class FullCanvas extends MIDlet
{
  private Display  display; 
  private MyCanvas canvas; 
  public FullCanvas ()
 {
    display = Display.getDisplay(this);
    canvas  = new MyCanvas (this);
  }
  protected void startApp()
  {
    display.setCurrent( canvas );
  }
  protected void pauseApp()
  { 
  }
  protected void destroyApp( boolean unconditional )
  { 
  }
  public void exitMIDlet()
  {
    destroyApp(true);
    notifyDestroyed();
  }
}
//定义画布类
class MyCanvas extends Canvas implements CommandListener
{
  private Command exit; 
  private FullCanvas Example;
  public MyCanvas (FullCanvas Example)
  {
    this.Example = Example;
    exit = new Command("Exit", Command.EXIT, 1);
    addCommand(exit);
    setCommandListener(this);
  } 
  //重写Canvas类的绘画方法
  protected void paint(Graphics graphics)
  {
      //将画笔颜色设置为白色
      graphics.setColor(255,255,255);
      //用白色填充整个画布范围,达到清屏的效果
      graphics.fillRect(0, 0, getWidth(), getHeight());
   }
  public void commandAction(Command command, Displayable displayable)
  {
    if (command == exit)
    {
     Example.exitMIDlet();
    }
  }
}

⌨️ 快捷键说明

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