我的漫漫程序之旅
专注于JavaWeb开发
我的第一个J2ME 程序
package
com;
import
javax.microedition.lcdui.Alert;
import
javax.microedition.lcdui.AlertType;
import
javax.microedition.lcdui.Command;
import
javax.microedition.lcdui.CommandListener;
import
javax.microedition.lcdui.Display;
import
javax.microedition.lcdui.Displayable;
import
javax.microedition.lcdui.TextBox;
import
javax.microedition.lcdui.TextField;
import
javax.microedition.lcdui.Ticker;
import
javax.microedition.midlet.MIDlet;
import
javax.microedition.midlet.MIDletStateChangeException;
/** */
/**
*****************************************************************************
*
*
@author
zdw
*
*/
public
class
TextTest
extends
MIDlet
implements
CommandListener
{
//
文本框
private
TextBox tbx
=
null
;
//
控制输入输出的类
private
Display display
=
Display.getDisplay(
this
);
//
命令菜单(清除)
private
Command clear;
//
得到鼠标位置
private
Command getCursorPos;
//
输入限制
private
Command astrict;
//
发送
private
Command send;
//
退出
private
Command exit;
public
TextTest()
{
//
初始化textBox
tbx
=
new
TextBox(
"
测试标题
"
,
"
测试内容
"
,
200
, TextField.ANY);
//
设置为当前显示
display.setCurrent(tbx);
//
清除菜单
clear
=
new
Command(
"
清空
"
, Command.SCREEN,
1
);
//
光标位置菜单
getCursorPos
=
new
Command(
"
光标位置
"
, Command.SCREEN,
1
);
//
输入限制菜单
astrict
=
new
Command(
"
只能输入数字
"
, Command.SCREEN,
1
);
//
发送菜单
send
=
new
Command(
"
发送
"
, Command.SCREEN,
1
);
//
退出菜单
exit
=
new
Command(
"
退出
"
, Command.EXIT,
1
);
tbx.addCommand(clear);
tbx.addCommand(getCursorPos);
tbx.addCommand(astrict);
tbx.addCommand(send);
tbx.addCommand(exit);
//
添加Ticker(显示在TextBox上方)
tbx.setTicker(
new
Ticker(
"
短信编辑器
"
));
//
添加事件监听器
tbx.setCommandListener(
this
);
}
//
Alert的初始函数
public
void
initAlert()
{
Alert alert
=
new
Alert(
"
提示
"
,
"
发送成功
"
,
null
, AlertType.INFO);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert);
}
//
事件处理
public
void
commandAction(Command cmd, Displayable dis)
{
if
(cmd
==
getCursorPos)
{
System.out.println(
"
光标位置为:
"
+
tbx.getCaretPosition());
}
if
(cmd
==
clear)
{
tbx.setString(
""
);
}
if
(cmd.getLabel().equals(
"
只能输入数字
"
))
{
tbx.setConstraints(TextField.DECIMAL);
tbx.removeCommand(astrict);
astrict
=
new
Command(
"
取消限制
"
, Command.SCREEN,
1
);
tbx.addCommand(astrict);
}
if
(cmd.getLabel().equals(
"
取消限制
"
))
{
tbx.setConstraints(TextField.ANY);
tbx.removeCommand(astrict);
astrict
=
new
Command(
"
只能输入数字
"
, Command.SCREEN,
1
);
tbx.addCommand(astrict);
}
if
(cmd.getCommandType()
==
Command.EXIT)
{
this
.notifyDestroyed();
}
if
(cmd
==
send)
{
this
.initAlert();
}
}
protected
void
destroyApp(
boolean
arg0)
throws
MIDletStateChangeException
{
}
protected
void
pauseApp()
{
}
protected
void
startApp()
throws
MIDletStateChangeException
{
}
}
posted on 2008-06-23 12:55
々上善若水々
阅读(75)
评论(0)
编辑
收藏
所属分类:
J2SE
、
J2ME
IT新闻
新用户注册
刷新评论列表
标题
姓名
主页
验证码
*
内容(请不要发表任何与政治相关的内容)
Remember Me?
登录
使用高级评论
新用户注册
返回页首
恢复上次提交
[使用Ctrl+Enter键可以直接提交]
该文被作者在 2008-06-23 13:47 编辑过
相关文章:
统计一个字符串的重复字符出现的字数
删除指定目录下的所有空文件夹
修改MyEclipse or Eclipse的启动画面
JDBC利用游标分页查询
获取昨天的日期字符串
我的第一个J2ME 程序
JDBC数据库连接语句大全
Eclipse和MyEclipse工程描述符详解
Java中Native关键字的作用
Java中连接字符串时+号与StringBuilder的选用
相关链接:
网站导航:
博客园
BlogJava
博客生活
IT博客网
C++博客
PHP博客
博客园社区
管理博客
教师博客
天文博客
汽车博客
足球博客
股票博客
电子博客
管理
导航
首页
新随笔
联系
管理
<
2008年12月
>
日
一
二
三
四
五
六
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
统计
随笔 - 21
文章 - 279
评论 - 140
引用 - 0
留言簿
(12)
给我留言
查看公开留言
查看私人留言
随笔档案
(24)
2008年11月 (3)
2008年9月 (2)
2008年8月 (1)
2008年7月 (2)
2008年6月 (2)
2008年5月 (9)
2008年4月 (2)
2007年12月 (3)
文章分类
(277)
AJAX(7)
(rss)
Hibernate(3)
(rss)
J2ME(2)
(rss)
J2SE(36)
(rss)
JavaScript(57)
(rss)
JavaWeb(24)
(rss)
Java笔试与面试(52)
(rss)
opensource(13)
(rss)
Spring(9)
(rss)
SSH整合系列(2)
(rss)
Struts1.x(3)
(rss)
Struts2(11)
(rss)
WebService(14)
(rss)
数据库(10)
(rss)
数据结构与算法(7)
(rss)
设计模式(17)
(rss)
软件测试(10)
(rss)
文章档案
(228)
2008年12月 (1)
2008年11月 (4)
2008年10月 (2)
2008年9月 (2)
2008年8月 (10)
2008年7月 (22)
2008年6月 (13)
2008年5月 (45)
2008年4月 (17)
2008年3月 (5)
2008年2月 (11)
2008年1月 (27)
2007年12月 (45)
2007年11月 (24)
搜索
最新评论
1. re: javascript文件夹选择框的两种解决方案
我用了第一中方法。可是还有一个问题,就是选择了远程计算机上的文件夹,怎么获得全路径?
--justin
2. re: Flash图表(FusionChartsV3)的简单应用
就是说网页上有多个图表,当页面加载时所有动画效果已经完成,下边的图表无法看到动画的效果,只是个最终的结果,如果有循环控制的话就可以看到下边的图表时仍然可以看到动画效果,也相当于不断刷新自己吧!谢谢
--左
3. re: Flash图表(FusionChartsV3)的简单应用
不明白你说的什么意思,不断刷新Chart自己?
--々上善若水々
4. re: Flash图表(FusionChartsV3)的简单应用
请问一下楼主,如何让FusionCharts生成的图表在网页上循环播放啊,谢谢!!!
--左
5. re: Struts1.2实现单文件上传
方法太牛比了。mail:yaoyao19851023@163.com
--yaoyao
阅读排行榜
1. 一道Struts面试题(3002)
2. javascript文件夹选择框的两种解决方案(2293)
3. ExtJS & GTGrid 简单用户管理(1833)
4. jexcelapi使用小记(1748)
5. Flash图表(FusionChartsV3)的简单应用 (1699)
评论排行榜
1. Flash图表(FusionChartsV3)的简单应用 (19)
2. [原创]J2ME/J2EE实现用户登录交互(7)
3. Flash图片轮换显示的效果抽取(7)
4. ExtJS & GTGrid 简单用户管理(6)
5. StringBuffer和StringBuilder添加null值的误导(5)