选择显示字体大小

保护自己的midlet程序之二:timeprotector

第一部分介绍了protector,并实现了一个最简单的protector:onceprotector
第二部分将实现一个timeprotector
我们先来设想他所具有的功能:
1。没有到指定时间,他是处于激活状态的(check函数返回true);
2。过了指定时间,他就不能激活;
3。一旦过期,即使用户调整了时间也不再激活。

嗯,明确了目的,下面就来继续。
涉及到了时间问题,就来说说如何处理时间。midp有date类型,但是提供的功能非常有限。
构造函数无法接受人们熟悉的字符串来初始化。
我们必须使用calendar来做这些工作,当然,如果long在你眼里看来就是time(黑客帝国?)。。。
我是这样处理的,看timeprotector的构造函数:

public timeprotector(midlet app,int year,int month,int date)
{
super(app);
calendar c=calendar.getinstance();
c.set(calendar.year,year);
c.set(calendar.month,month-1);
c.set(calendar.date,date);
date_=c.gettime();
}

这里要注意一个问题,就是month-1的问题,set month 9就是10月的意思。

timeprotector有一个字段date_,可以用date_.gettime()直接和system.currenttimemillis()比较大小。

那么我们如何实现第三个设想呢?如何做到即使用户修改时间也无法继续使用呢?
不妨再用用rms来做个标记,表明已经过期:)
下面就是那个决定命运的check函数:

public boolean check()
{
boolean r=true;
try
{
recordstore rs=recordstore.openrecordstore(namerms,true);
recordenumeration e=rs.enumeraterecords(null,null,false);
if(e.hasnextelement())
{
r=false;
}
else
{
if(date_.gettime()<system.currenttimemillis())
&#123;
writetag(rs);
r=false;
&#125;
else
&#123;
r=true;
&#125;
&#125;
rs.closerecordstore();
&#125;
catch(exception ex)
&#123;
r=false;
&#125;
if(!r)
showui();

return r;
&#125;

好了,这就是我的timeprotector的实现,你是怎么实现的呢?

timeprotector的使用:
在startapp的开头加入if(!new timeprotector(this,2005,10,19).check())return;

就是这么简单。准备好,下一篇就来实现snprotector:)
有意见或建议请联系vmlinuxx@gmail.com,共同学习,共同提高:)


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons