sccanvas.java

来自「J2ME手机游戏编程入门源码 16事例源码 可用手机顽童软件测试」· Java 代码 · 共 46 行

JAVA
46
字号
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;

public class SCCanvas extends Canvas {
  private Display  display;
  
  public SCCanvas(Display d) {
    super();
    display = d;
  }

  void start() {
    display.setCurrent(this);
    repaint();
  }

  public void paint(Graphics g) {
    // Clear the canvas
    g.setColor(0, 0, 0);        // black
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(255, 255, 255);  // white

    // Get the supported sound content types
    String[] contentTypes = Manager.getSupportedContentTypes(null);

    // Draw the supported sound content types
    int y = 0;
    for (int i = 0; i < contentTypes.length; i++) {
      // Draw the content type
      g.drawString(contentTypes[i], 0, y, Graphics.TOP | Graphics.LEFT);
      y += Font.getDefaultFont().getHeight();

      // Play a tone if tone generation is supported
      if (contentTypes[i] == "audio/x-tone-seq") {
        try {
          // play middle C (C4) for two seconds (2000ms) at maximum volume (100)
          Manager.playTone(ToneControl.C4, 2000, 100);
        }
        catch(MediaException me) {
        }
      }
    }
  }
}

⌨️ 快捷键说明

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