displayable1.java

来自「手机上画线」· Java 代码 · 共 52 行

JAVA
52
字号

import javax.microedition.lcdui.*;

public class Displayable1 extends Canvas implements CommandListener {
  /** Constructor */
  public Displayable1() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**Component initialization*/
  private void jbInit() throws Exception {
    // Set up this Displayable to listen to command events
    setCommandListener(this);
    // add the Exit command
    addCommand(new Command("Exit", Command.EXIT, 1));
  }

  /**Handle command events*/
  public void commandAction(Command command, Displayable displayable) {
    /** @todo Add command handling code */
    if (command.getCommandType() == Command.EXIT) {
// stop the MIDlet
      MIDlet1.quitApp();
    }
  }

  /** Required paint implementation */
  protected void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();
// Fill the background using black
    g.setColor(0);
    g.fillRect(0, 0, width, height);
// White horizontal line
    g.setColor(0xFFFFFF);
    for(int i=0;i<=11;i++){
      g.drawLine(0,0,width,0);
      g.translate(0,height/10);
    }
    g.translate(-g.getTranslateX(),-g.getTranslateY());
    for(int i=0;i<=10;i++){
      g.drawLine(0,0,0,height);
      g.translate(width/10,0);
    }
  }
}

⌨️ 快捷键说明

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