此实例为本人原创的电话呼叫程序,用户输入号码进行拨号,由于本人一直是搞低级UI开发的,所以并没有用高级控件做输出体。
框架代码1 - Constant
import javax.microedition.lcdui.Graphics;
/**
* @author 空白节奏
* */
public class Constant
{
public static final int SCR_WIDTH = 240;
public static final int SCR_HEIGHT = 320;
public static final int SCR_CENTERW = 120;
public static final int SCR_CENTERH = 160;
public static final byte FPS = 20;
public static final String rms_name = "RMS_name";
//走程状态
public static int MIDLetState = 0;
public static final int MIDLetState_LOGO = 1;
public static final int MIDLetState_MENU = 2;
public static final int KEY_UP = -1;
public static final int KEY_DOWN = -2;
public static final int KEY_LEFT = -3;
public static final int KEY_RIGHT = -4;
public static final int KEY_FIRE = -5;
public static final int KEY_LSOFT = -6;
public static final int KEY_RSOFT = -7;
public static final int KEY_CLEAR = -8;
public static final int KEY_SEND = -10;
public static final int KEY_END = -11;
public static final int KEY_ASTERISK = 42;// *
public static final int KEY_POUND = 35;// #
public static final int KEY_NUM0 = 48;
public static final int KEY_NUM1 = 49;
public static final int KEY_NUM2 = 50;
public static final int KEY_NUM3 = 51;
public static final int KEY_NUM4 = 52;
public static final int KEY_NUM5 = 53;
public static final int KEY_NUM6 = 54;
public static final int KEY_NUM7 = 55;
public static final int KEY_NUM8 = 56;
public static final int KEY_NUM9 = 57;
public static final int GLT = Graphics.LEFT | Graphics.TOP;
public static final int GRT = Graphics.RIGHT | Graphics.TOP;
public static final int GLB = Graphics.LEFT | Graphics.BOTTOM;
public static final int GRB = Graphics.RIGHT | Graphics.BOTTOM;
public static final int GTH = Graphics.TOP | Graphics.HCENTER;
public static final int GBH = Graphics.BOTTOM | Graphics.HCENTER;
public static final int GLV = Graphics.LEFT | Graphics.VCENTER;
public static final int GRV = Graphics.RIGHT | Graphics.VCENTER;
public static final int GHV = Graphics.HCENTER | Graphics.VCENTER;
}
框架代码2 - GameMIDlet
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
/**
* @author 空白节奏
* */
public class GameMIDlet extends MIDlet
{
static GameMIDlet gameMIDlet = null;
Displayable current = null;
GameMaster gm = null;
public GameMIDlet()
{
gameMIDlet = this;
}
protected void startApp()
{
current = Display.getDisplay(this).getCurrent();
if(current == null)
{
gm = new GameMaster(this);
Display.getDisplay(this).setCurrent(gm);
}
else
{
Display.getDisplay(this).setCurrent(current);
}
}
protected void pauseApp()
{
}
protected void destroyApp(boolean arg0)
{
}
public static void quitApp()
{
gameMIDlet.destroyApp(true);
gameMIDlet.notifyDestroyed();
gameMIDlet = null;
}
}
框架代码3 - GameMaster
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* @author 空白节奏
* */
public class GameMaster extends Canvas implements Runnable
{
private boolean isStart = false;
private Image img_buffer = null;
private Graphics gg;
private boolean isFullScreen = true;
call c = null;
GameMIDlet gml = null;
public GameMaster(GameMIDlet gml)
{
this.gml = gml;
init();
setFullScreenMode(isFullScreen);
isStart = true;
new Thread(this).start();
}
public void paint(Graphics g)
{
gg.setColor(0);
gg.setClip(0, 0, Constant.SCR_WIDTH, Constant.SCR_HEIGHT);
gg.fillRect(0, 0, Constant.SCR_WIDTH, Constant.SCR_HEIGHT);
c.paint(gg);
g.drawImage(img_buffer, 0, 0, Constant.GLT);
}
public void update()
{
c.updata();
}
public void keyPressed(int keyCode)
{
}
public void keyReleased(int keyCode)
{
}
public void pointerPressed(int x, int y)
{
c.pointerPressed(x, y, gml);
}
public void init()
{
c = new call();
img_buffer = Image.createImage(Constant.SCR_WIDTH, Constant.SCR_HEIGHT);
gg = img_buffer.getGraphics();
}
long startTime = 0;
long timeTaken = 0;
public void run()
{
while (isStart)
{
startTime = System.currentTimeMillis();
update();
repaint();
timeTaken = System.currentTimeMillis() - startTime;
if(timeTaken < 1000 / Constant.FPS)
{
try
{
Thread.sleep(1000 / Constant.FPS - timeTaken);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}
}
逻辑代码 - call
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.Graphics;
/**
* @author 空白节奏
* */
public class call
{
callButten[] cb = null;
Vector v = new Vector(0, 1);
String stError = "";
public call()
{
init();
}
public void init()
{
cb = new callButten[13];
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
cb[(i*3)+j] = new callButten(1+(i*3)+j+"", 20+(j*40), 30+(i*50), 30, 30, -1, 0);
}
}
cb[9] = new callButten("0", 150, 130, 30, 30, -1, 0);
cb[10] = new callButten("拨打", 150, 30, 60, 30, -1, 0);
cb[11] = new callButten("清除", 150, 80, 60, 30, -1, 0);
cb[12] = new callButten("退出", 20, 220, 180, 30, -1, 0);
}
public void paint(Graphics g)
{
for(int i = 0; i < cb.length; i++)
{
cb[i].paint(g);
}
g.setColor(-1);
g.fillRect(20, 180, 180, 30);
if(v.size() > 0)
{
g.setColor(0);
for(int i = 0; i < v.size(); i++)
{
g.drawString(v.elementAt(i).toString(), 22+(i*8), 182, 20);
}
}
g.setColor(255,0,0);
g.drawString(stError, 10, 20, 20);
}
public void updata()
{
}
public void pointerPressed(int x, int y, GameMIDlet gm)
{
for(int i = 0; i < cb.length; i++)
{
if(x > cb[i].x && x < (cb[i].x + cb[i].width) && y > cb[i].y && y < (cb[i].y + cb[i].hight))
{
if(i < 10)
{
v.addElement(cb[i].num);
}
else if(i == 10)
{
callplat(gm);
}
else if(i == 11)
{
if(v.size() > 0)
v.removeElementAt(v.size()-1);
}
else if(i == 12)
{
gm.quitApp();
}
}
}
}
public void callplat(GameMIDlet gm)
{
String stURL = "";
for(int i=0; i<v.size(); i++)
{
stURL += v.elementAt(i).toString();
}
try {
if(!stURL.equals(""))
{
gm.platformRequest("tel:"+stURL);
}
} catch (ConnectionNotFoundException e) {
stError = e.getMessage();
}
}
}
class callButten
{
String num;
int x, y, width, hight;
int bgColor, strColor;
callButten(){}
callButten(String num, int x, int y, int width, int hight, int bgColor, int strColor)
{
this.num = num;
this.x = x;
this.y = y;
this.width = width;
this.hight = hight;
this.bgColor = bgColor;
this.strColor = strColor;
}
void paint(Graphics g)
{
g.setColor(bgColor);
g.fillRect(x, y, width, hight);
g.setColor(strColor);
g.drawString(num, x+(width>>1)-5, y+(hight>>1)-5, 20);
}
}
实现了J2ME的打电话功能,需要MIDP2.0支持,需注意的是,有些机器不支持platformRequest方法,比如我的E680G就不支持,并且API对此方法的描述也是雷人,- - 大概意思是“此方法应该能够拨打指定电话号码”,应该二字很雷人。
转载请声明出处。
附件1就是此程序实例。
附件2是jar。
分享到:
相关推荐
j2me 实现打电话功能 call phone
J2ME是Java技术的一个重要分支,主要用于嵌入式设备,如移动电话、PDA等,具有轻量级、跨平台的特点。这个项目为初学者提供了实际操作和理解游戏编程的机会,特别对于想要了解如何在小型设备上构建游戏的开发者来说...
J2ME,全称Java 2 Micro Edition,是Java平台的一个子集,专门用于资源有限的设备,如移动电话和嵌入式系统。在本文中,我们将深入探讨J2ME在手机游戏开发中的应用,以及如何利用它进行毕业论文的研究。 首先,...
例如,对于“打电话给张三”这样的指令,自然语言处理技术可以帮助系统识别出“打电话”和“张三”这两个关键信息点。 3. **J2ME平台**:为满足资源受限设备的需求而设计,具有良好的跨平台能力和强大的后台集成能力...
实现基本的添加、快速查找、查看、修改、删除功能,同时还能打电话和发短信的功能,其中包括打包好的jar包,可以直接在手机上运行。解压密码:robin
在功能方面,“生益通”具备了核心的网络电话功能,允许用户通过互联网进行语音通话,降低了通信成本。这需要对网络协议有深入理解,比如可能用到了UDP(User Datagram Protocol)或者TCP(Transmission Control ...
5. **J2ME开发环境**:开发J2ME应用,需要安装Java Development Kit (JDK) 并配置环境变量,以及J2ME Wireless Toolkit (WTK),用于创建、编译和测试MIDlet(J2ME应用程序)。在WTK中,`src`目录存放源代码,`res`...
J2ME(Java 2 Micro Edition)是Java技术的一个分支,专为资源有限的设备如移动电话和平板电脑设计,使得开发者能够创建跨平台的游戏应用。 首先,我们需要了解J2ME的基础知识。J2ME由配置(Configurations)和 ...
对象是现实世界中实体的抽象,包含属性(如手机的颜色、重量)和方法(如手机的打电话功能),并且可以通过继承实现类之间的层次结构。 Java应用程序主要包括两种类型:Java应用程序(Java Application)和Java小...
5.19 调用拨号按钮——打电话CALL_BUTTON 5.20 DPAD按键处理——onKeyDown事件与Layout坐标交互 5.21 任务管理器正在运行的程序——RunningTaskInfo 5.22 动态更改屏幕方向——LANDSCAPE与PORTRAIT 5.23 系统设置...
Handset Handset Handset Handset Manufacturers Manufacturers Manufacturers Manufacturers 电话制造商 ASUSTeK Computer Inc. 华硕 Garmin International, Inc. HTC Corporation ( 多普达的母公司 ) 宏达电子 ...