📄 main.java~39~
字号:
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(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 int 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 + -