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

📄 main.java~44~

📁 一个很好的按键测试的类工具代码,它可以测试不同手机的键值,还可以测试不同手机的屏幕的宽度和高度,下载安装的手机里可以很好的使用 可以给广大程序员带来很大方便,愿意与大家一起学习
💻 JAVA~44~
字号:
package j2mekey;

import javax.microedition.lcdui.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class Main
  extends Canvas implements Runnable
{
  private int SCREENWIDTH; // 屏幕高和宽
  private int SCREENHEIGHT;

  public Main()
  {
    this.setFullScreenMode(true);
    this.SCREENWIDTH = getWidth();
    this.SCREENHEIGHT = getHeight();
    new Thread(this).start();
  }

  Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
  protected void paint(Graphics g)
  {
    this.SCREENWIDTH = getWidth();
    this.SCREENHEIGHT = getHeight();
    g.setColor(0);
    g.setClip(0, 0, SCREENWIDTH, SCREENHEIGHT);
    g.fillRect(0, 0, SCREENWIDTH, SCREENHEIGHT);
    g.setColor(0xffff00);
    g.setFont(font);
    //System.out.println("eeee = "+ (Graphics.VCENTER |Graphics.HCENTER));
    drawString(g, font, SCREENWIDTH + "x" + SCREENHEIGHT, SCREENWIDTH / 2,
               SCREENHEIGHT / 2 - 20,
               Graphics.VCENTER | Graphics.HCENTER, 0x00ffff00);
    drawString(g, font, String.valueOf(TEST_KEY), SCREENWIDTH / 2,
               SCREENHEIGHT / 2,
               Graphics.VCENTER | Graphics.HCENTER,
               0x00ffff00);
  }

  private long spendTime;
  public void run()
  {
    while (true)
    {
      long startTime = System.currentTimeMillis();

      RefreshScreen();

      spendTime = System.currentTimeMillis() - startTime;
      if (spendTime < 100)
      {
        try
        {
          synchronized (this)
          {
            Thread.sleep(100 - spendTime);
          }
        }
        catch (Exception e)
        {
        }
      }
    }
  }

  private void RefreshScreen()
  {
    try
    {
      repaint(0, 0, SCREENWIDTH, SCREENHEIGHT);
      serviceRepaints();
    }
    catch (Exception e)
    {}
  }

  int TEST_KEY = 0;
  public final void keyPressed(int keyCode)
  {
    TEST_KEY = keyCode;
  }

  public final void keyReleased(int keyCode)
  {

  }

  public static final void drawString(Graphics g, Font font, String str, int x, int y, int Align, int fcolor)
  {
    int w, h;
    int nx, ny;

    str = str.trim();

    w = font.stringWidth(str);
    h = font.getHeight();
    nx = x;
    ny = y;

    if ( (Align & Graphics.HCENTER) == Graphics.HCENTER)
    {
      nx -= w / 2;
    }
    else if ( (Align & Graphics.RIGHT) == Graphics.RIGHT)
    {
      nx -= w;
    }

    if ( (Align & Graphics.VCENTER) == Graphics.VCENTER)
    {
      ny -= h / 2;
    }
    else if ( (Align & Graphics.BOTTOM) == Graphics.BOTTOM)
    {
      ny -= h;
    }
    g.setFont(font);
    g.setColor(fcolor);
    g.drawString(str, nx, ny, Graphics.LEFT | Graphics.TOP);
    //return h;
  }
}

⌨️ 快捷键说明

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