📄 main.java
字号:
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.media.Manager;
/**
*
* <P>标题:Main类 </P>
* <P>描述:手机测试.</P>
* <P>作者:supren lee</P>
* <p>E-mail&MSN:supern_lee@msn.com</p>
* <p>主页:http://www.votbar.com</p>
* <P>时间:V1.0 2006.9.18</P>
*
*/
public class Main extends Canvas implements Runnable {
private static final int MENU=0;
private static final int MAIN=1;
private static final int KEY=2;
private static final int ABOUT=3;
private int state;
private int key;
private String cldc;
private String midp;
private boolean too=true;
private int width=100;
private int height=100;
private static String[] menu_text={
"主要信息",
"手机键值",
"关于我们",
"退出程序"
};
private int point=0;
private int count=0;
private int x=0;//绘画坐标
private int y=0;
/**
* 构造函数
*
*/
public Main(){
cldc=System.getProperty("microedition.configuration");
midp=System.getProperty("microedition.profiles");
if(midp.equals("MIDP-1.0")){
setFullScreenMode(true);
too=false;
}
state=MENU;
new Thread(this).start();
}
protected void paint(Graphics g) {
clean(g,width,height);
switch(state){
case MENU:
if(!too){
g.setColor(0x00FF00);
g.drawString("MIDP1.0的手机,",0,0,Graphics.LEFT|Graphics.TOP);
g.drawString("不支持后面的测",0,20,Graphics.LEFT|Graphics.TOP);
g.drawString("试,按任意键退出",0,40,Graphics.LEFT|Graphics.TOP);
}else{
width=getWidth();
height=getHeight();
g.setColor(0xFFFFFF);
if(count%2==0){
g.fillTriangle(width/2,height/2-30,width/2-5,height/2-20,width/2+5,height/2-20);
g.fillTriangle(width/2,height/2+30,width/2-5,height/2+20,width/2+5,height/2+20);
}else{
g.fillTriangle(width/2,height/2-30,width/2-3,height/2-20,width/2+3,height/2-20);
g.fillTriangle(width/2,height/2+30,width/2-3,height/2+20,width/2+3,height/2+20);
}
g.setColor(0x00FF00);
g.drawString(menu_text[point],width/2,height/2-7,Graphics.HCENTER|Graphics.TOP);
g.drawString("按2,5,8键",width/2,height,Graphics.HCENTER|Graphics.BOTTOM);
}
break;
case KEY:
g.setColor(0xFFFFFF);
g.drawString("键值是:",width/2,height/2-20,Graphics.HCENTER|Graphics.TOP);
g.setColor(0x00FF00);
g.drawString(""+key,width/2,height/2,Graphics.HCENTER|Graphics.TOP);
g.drawString("按5键退出",width/2,height,Graphics.HCENTER|Graphics.BOTTOM);
break;
case MAIN:
g.setClip(0,0,width,height-20);
//内存
g.setColor(0x00FF00);
g.drawString(">>>",x,y,Graphics.LEFT|Graphics.TOP);
g.setColor(0xFFFFFF);
long total=Runtime.getRuntime().totalMemory();
g.drawString("总共内存:"+total,x,y+20,Graphics.LEFT|Graphics.TOP);
long free=Runtime.getRuntime().freeMemory();
g.drawString("可用内存:"+free,x,y+40,Graphics.LEFT|Graphics.TOP);
//屏幕
g.setColor(0x00FF00);
g.drawString(">>>",x,y+60,Graphics.LEFT|Graphics.TOP);
g.setColor(0xFFFFFF);
g.drawString("屏幕宽:"+width,x,y+80,Graphics.LEFT|Graphics.TOP);
g.drawString("屏幕高:"+height,x,y+100,Graphics.LEFT|Graphics.TOP);
//字体:
g.setColor(0x00FF00);
g.drawString(">>>",x,y+120,Graphics.LEFT|Graphics.TOP);
g.setColor(0xFFFFFF);
Font big=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_LARGE);
int fontw=big.stringWidth("国");
int fonth=big.getHeight();
g.drawString("大字体(宽&高):"+fontw+"&"+fonth,x,y+140,Graphics.LEFT|Graphics.TOP);
Font normal=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_MEDIUM);
fontw=normal.stringWidth("国");
fonth=normal.getHeight();
g.drawString("中字体(宽&高):"+fontw+"&"+fonth,x,y+160,Graphics.LEFT|Graphics.TOP);
Font small=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL);
fontw=small.stringWidth("国");
fonth=small.getHeight();
g.drawString("小字体(宽&高):"+fontw+"&"+fonth,x,y+180,Graphics.LEFT|Graphics.TOP);
//系统属性
g.setColor(0x00FF00);
g.drawString(">>>",x,y+200,Graphics.LEFT|Graphics.TOP);
g.setColor(0xFFFFFF);
g.drawString("CLDC:"+cldc,x,y+220,Graphics.LEFT|Graphics.TOP);
g.drawString("MIDP:"+midp,x,y+240,Graphics.LEFT|Graphics.TOP);
String platform=System.getProperty("microedition.platform");
g.drawString("平台:"+platform,x,y+260,Graphics.LEFT|Graphics.TOP);
String encoding=System.getProperty("microedition.encoding");
g.drawString("编码:"+encoding,x,y+280,Graphics.LEFT|Graphics.TOP);
String locale=System.getProperty("microedition.locale");
g.drawString("地区:"+locale,x,y+300,Graphics.LEFT|Graphics.TOP);
String m3g=System.getProperty("microedition.m3g.version");
g.drawString("3D:"+m3g,x,y+320,Graphics.LEFT|Graphics.TOP);
String sms=System.getProperty("wireless.messaging.sms.smsc");
g.drawString("WMA:"+sms,x,y+340,Graphics.LEFT|Graphics.TOP);
String mmapi=System.getProperty("microedition.media.version");
g.drawString("MMAPI:"+mmapi,x,y+360,Graphics.LEFT|Graphics.TOP);
String pim=System.getProperty("microedition.pim.version");
g.drawString("PIM:"+pim,x,y+380,Graphics.LEFT|Graphics.TOP);
String bluetooth=System.getProperty("bluetooth.api.version");
g.drawString("BlueTooth:"+bluetooth,x,y+400,Graphics.LEFT|Graphics.TOP);
String FileConnection=System.getProperty("microedition.io.file.FileConnection.version");
g.drawString("FileConnection:"+FileConnection,x,y+420,Graphics.LEFT|Graphics.TOP);
//媒体格式
g.setColor(0x00FF00);
g.drawString(">>>",x,y+440,Graphics.LEFT|Graphics.TOP);
g.setColor(0xFFFFFF);
String[] mime=Manager.getSupportedContentTypes(null);
g.drawString("支持的媒体格式:",x,y+460,Graphics.LEFT|Graphics.TOP);
for(int i=0;i<mime.length;i++){
g.drawString(mime[i],x,y+480+i*20,Graphics.LEFT|Graphics.TOP);
}
g.setClip(0,0,width,height);
g.setColor(0x00FF00);
g.drawString("按2,4,5,6,8键",width/2,height,Graphics.HCENTER|Graphics.BOTTOM);
break;
case ABOUT:
g.setColor(0x00FF00);
g.drawString("作者:Supern Lee",width/2,10,Graphics.HCENTER|Graphics.TOP);
g.drawString("Email:supern.lee@",width/2,30,Graphics.HCENTER|Graphics.TOP);
g.drawString(" gmail.com",width/2,50,Graphics.HCENTER|Graphics.TOP);
g.drawString("主页:http://www.",width/2,70,Graphics.HCENTER|Graphics.TOP);
g.drawString(" votbar.com",width/2,90,Graphics.HCENTER|Graphics.TOP);
g.drawString("按5键退出",width/2,height,Graphics.HCENTER|Graphics.BOTTOM);
break;
}
}
private void clean(Graphics g,int width,int height) {
g.setColor(0x000000);
g.fillRect(0,0,width,height);
}
public void run() {
try{
while(true){
long start=System.currentTimeMillis();
switch(state){
case MENU:
count++;
break;
case KEY:
break;
case MAIN:
break;
case ABOUT:
break;
}
repaint();
long end=System.currentTimeMillis();
if(end-start<100)
Thread.sleep(100-(end-start));
}
}catch(Exception e){}
}
public void keyPressed(int keyCode){
switch(state){
case MENU:
if(!too){
Midlet.instance.Exit();
}else{
switch(keyCode){
case KEY_NUM2 :
if(point>0)
point--;
else
point=menu_text.length-1;
break;
case KEY_NUM8:
if(point<menu_text.length-1)
point++;
else
point=0;
break;
case KEY_NUM5:
if(point==menu_text.length-1){
Midlet.instance.Exit();
}else{
state=point+1;
}
break;
}
}
break;
case KEY:
key=keyCode;
if(key==KEY_NUM5){
state=MENU;
}
break;
case MAIN:
switch(keyCode){
case KEY_NUM2 :
y+=20;
break;
case KEY_NUM8:
y-=20;
break;
case KEY_NUM4:
x-=20;
break;
case KEY_NUM6:
x+=20;
break;
case KEY_NUM5:
state=MENU;
break;
}
break;
case ABOUT:
if(keyCode==KEY_NUM5)
state=MENU;
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -