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

📄 displayable1.java

📁 自己做的作业
💻 JAVA
字号:

import javax.microedition.lcdui.*;

public class Displayable1 extends Canvas implements CommandListener {
  private int currentFace=Font.FACE_SYSTEM;

  private Command monospaceCommand=new Command("monospace",Command.ITEM,1);
  private Command proportionalCommand=new Command("proportional",Command.ITEM,1);
  private Command systemCommand=new Command("system",Command.ITEM,1);
  /** 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));
    setCommandListener(this);
    addCommand(monospaceCommand);
    addCommand(proportionalCommand);
    addCommand(systemCommand);
  }

  /**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();
    }
    if(command==monospaceCommand){
    currentFace=Font.FACE_MONOSPACE;
    }else if(command==proportionalCommand){
    currentFace=Font.FACE_PROPORTIONAL;
  }else if (command==systemCommand){
  currentFace=Font.FACE_SYSTEM;
  }
  repaint();
  }

  /** Required paint implementation */
  protected void paint(Graphics g) {
    String title;
    int height = 0;

    g.setColor(0x0000000);
    g.fillRect(0,0,getWidth(),getHeight());

    g.setColor(0x00fffff);
    switch(currentFace){
    case Font.FACE_SYSTEM:
      title="System";
      break;
    case Font.FACE_PROPORTIONAL:
      title="Proportional";
      break;
    case Font.FACE_MONOSPACE:
      title="Monospaced";
      break;
    default:
      title="unknown";
      break;
    }
  g.drawString(title,0,0,Graphics.TOP|Graphics.LEFT);
  height+=g.getFont().getHeight();

  g.setFont(Font.getFont(currentFace,Font.STYLE_ITALIC,Font.SIZE_LARGE));
  g.drawString("Regular ital",0,height,Graphics.TOP|Graphics.LEFT);
  height+=g.getFont().getHeight();

  g.setFont(Font.getFont(currentFace,Font.STYLE_BOLD,Font.SIZE_LARGE));
  g.drawString("Bold plain",0,height,Graphics.TOP|Graphics.LEFT);
  height+=g.getFont().getHeight();

  g.setFont(Font.getFont(currentFace,Font.STYLE_BOLD|Font.STYLE_ITALIC,Font.SIZE_LARGE));
  g.drawString("Bold ital",0,height,Graphics.TOP|Graphics.LEFT);
  }
}

⌨️ 快捷键说明

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