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

📄 font_attribute_midlet.java

📁 本光盘是《J2ME无线移动游戏开发》一书的配套光盘
💻 JAVA
字号:
package ch10;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class Font_Attribute_MIDlet
    extends MIDlet
    implements CommandListener {
  //声明一个Display对象
  private Display display;

  //声明一个实现字体属性选择的Form类对象
  private Font_Attribute_Form faf;

  //声明一个实现字体绘制的Canvas类对象
  private Font_Attribute_Text fat;

  //声明一个退出按钮
  private Command exitCommand =
      new Command("退出", Command.EXIT, 1);

  //声明一个字体设置按钮
  private Command fontsCommand =
      new Command("字体设置", Command.SCREEN, 11);

  //声明一个确定按钮
  private Command okCommand =
      new Command("确定", Command.SCREEN, 2);

  /*
   1.构造器
   */
  public Font_Attribute_MIDlet() {
    display = Display.getDisplay(this);
    fat = new Font_Attribute_Text();
    display.setCurrent(fat);

    fat.addCommand(exitCommand);
    fat.addCommand(fontsCommand);
    fat.setCommandListener(this);
  }

  //启动应用程序
  public void startApp() {
  }

  //挂起应用程序
  public void pauseApp() {
  }

  //撤销应用程序
  public void destroyApp(boolean unconditional) {
  }

  /*
   2.响应按钮事件
   */
  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(true);
      notifyDestroyed();
    }
    else if (c == fontsCommand) {
      if (faf == null) {
        faf = new Font_Attribute_Form();
        faf.setFace(fat.getFace());
        faf.setStyle(fat.getStyle());
        faf.setSize(fat.getSize());
        faf.addCommand(okCommand);
        faf.setCommandListener(this);
      }
      display.setCurrent(faf);
    }
    else if (c == okCommand) {
      if (s == faf) {
        fat.setStyle(faf.getStyle());
        fat.setFace(faf.getFace());
        fat.setSize(faf.getSize());
      }
      display.setCurrent(fat);
    }
  }
}

⌨️ 快捷键说明

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