您的当前位置:首页>新品 > 正文

怎么看手机是否支持java?javax.lcdui.Display开发程序

来源:CSDN 时间:2023-01-29 13:43:12

为了查看各种各样的手机对Java的支持情况,特地编写了本程序。

程序是用J2ME开发的,很简单,只有两个类,编译打包成.jar文件后即可在手机上运行。

入口类


(资料图)

package org;

import javax.microedition.lcdui.Display;

import javax.microedition.midlet.MIDlet;

public class ViewMidlet extends MIDlet{

private J2MEInfo info;

public ViewMidlet(){

info=new J2MEInfo(this);

}

public Display getDisplay(){

return Display.getDisplay(this);

}

public void startApp() {

getDisplay().setCurrent(info);

}

public void pauseApp() {

}

public void destroyApp(boolean unconditional) {

}

}

处理类

package org;

import javax.bluetooth.LocalDevice;

import javax.microedition.lcdui.Alert;

import javax.microedition.lcdui.AlertType;

import javax.microedition.lcdui.Command;

import javax.microedition.lcdui.CommandListener;

import javax.microedition.lcdui.Displayable;

import javax.microedition.lcdui.Form;

import javax.microedition.lcdui.StringItem;

public class J2MEInfo extends Form implements CommandListener {

private ViewMidlet main;

private Command about;

private Command exit;

public J2MEInfo(ViewMidlet main) {

super("手机J2ME属性");

this.main=main;

init();

}

/**

* 初始化参数

*/

private void init() {

about = new Command("关于", Command.OK, 1);

exit = new Command("退出", Command.EXIT, 1);

this.addCommand(about);

this.addCommand(exit);

this.setCommandListener(this);

display();

}

/**

* 显示J2ME属性

*/

private void display() {

String[] keys = {"平台:", "编码:", "MIDP:", "CLDC:", "PIM:", "文件系统:"};

String[] values = {"microedition.platform", "microedition.encoding", "microedition.profiles",

"microedition.configuration", "microedition.pim.version", "microedition.io.file.FileConnection.version"};

for (int i = 0; i < keys.length; i++) {

StringItem item = new StringItem(keys[i], getInfo(1, values[i]));

this.append(item);

}

StringItem item2 = new StringItem("蓝牙:", getInfo(2, "bluetooth.api.version"));

this.append(item2);

}

/**

* 获取J2ME属性

* @param type   1代表从System类获取属性,2代表从LocalDevice类获取属性

* @param property  属性名

* @return    支持的版本号

*/

private String getInfo(int type, String property){

String value = null;

if(type == 1){

value = System.getProperty(property);

}else{

value = LocalDevice.getProperty(property);

}

if(value == null || value.trim().equals(""))

return "不支持";

else

return value;

}

public void commandAction(Command c, Displayable d) {  if (c == about) {   main.getDisplay().setCurrent(new Alert("关于/n",     "手机J2ME属性/n版本:1.0.2",null,AlertType.INFO), this);  } else if (c == exit) {   main.notifyDestroyed();   main.destroyApp(true);  } }}

标签:

最新新闻:

新闻放送
Top