在midp中没有提供dialog组件,但是提供了一个alert.alert的功能有限,因此写一个dialog组件是非常有必要的.本文将提供一个基于midp的dialog组件,你可以在应用程序中使用它,功能强大且非常方便.
首先我们写一个抽象类dialog,内容如下/* * created on 2004-7-10 * * todo to change the template for this generated file go to * window - preferences - java - code style - code templates */ 【程序编程相关:简单客户系统的权限控制实现】
当我们开发应用程序的时候,有的时候需要询问用户是不是要继续下面的操作,比如删除一个电话号码,然后根据用户的不同的动作进入不同的流程.这时候我们需要一个像样的dialog组件,很遗憾midp中并没有提供,但是我们可以用canvas自己写一个.下面将简单介绍这个组件的设计,然后给出测试的midlet的源代码.希望对读者有帮助! 【推荐阅读:编程手记之ANSI C篇-(一)通用连接】
import javax.microedition.lcdui.*; 【扩展信息:如何建立一个带登陆页面及角色的Strut】
/** * @author p2800 * * todo to change the template for this generated type comment go to window - * preferences - java - code style - code templates */
//the base class for a set of general-purpose//dialogs. to use, create a concrete instance//of this class, set the dialog listener,//and then call display.
public abstract class dialog{ protected display display; protected dialoglistener listener; protected displayable restore; private int eventid;
protected dialog(display display) { this.display = display; }
/** * @return returns the eventid. */ public int geteventid() { return eventid; }
/** * @param eventid * the eventid to set. */ public void seteventid(int eventid) { this.eventid = eventid; }
// dismisses the dialog, restoring the old // displayable, if any. this is normally done // by the dialog itself in response to commands, // but can also be called by the application // in response to some other event, such as a // timer expiration. the code is passed directly // to the dialog listener, if any.
... 下一页