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

📄 scanvas.java

📁 塞迪网校J2ME移动应用开发教程的所有源代码.
💻 JAVA
字号:
import javax.microedition.lcdui.*;

public class SCanvas extends Canvas {
  private Display display;
  
  public SCanvas(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

    // Draw the available screen size
    int y = 0;
    String screenSize = "Screen size: " + Integer.toString(getWidth()) + " x " +
      Integer.toString(getHeight());
    g.drawString(screenSize, 0, y, Graphics.TOP | Graphics.LEFT);

    // Draw the number of available colors
    y += Font.getDefaultFont().getHeight();
    String numColors = "# of colors: " + Integer.toString(display.numColors());
    g.drawString(numColors, 0, y, Graphics.TOP | Graphics.LEFT);

    // Draw the number of available alpha levels
    y += Font.getDefaultFont().getHeight();
    String numAlphas = "# of alphas: " + Integer.toString(display.numAlphaLevels());
    g.drawString(numAlphas, 0, y, Graphics.TOP | Graphics.LEFT);

    // Draw the amount of total and free memory
    Runtime runtime = Runtime.getRuntime();
    y += Font.getDefaultFont().getHeight();
    String totalMem = "Total memory: " + Long.toString(runtime.totalMemory() / 1024) + "KB";
    g.drawString(totalMem, 0, y, Graphics.TOP | Graphics.LEFT);
    y += Font.getDefaultFont().getHeight();
    String freeMem = "Free memory: " + Long.toString(runtime.freeMemory() / 1024) + "KB";
    g.drawString(freeMem, 0, y, Graphics.TOP | Graphics.LEFT);
  }
}

⌨️ 快捷键说明

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