张生工作室
一切皆有可能
语源科技BlogJava
::
首页
::
新随笔
::
联系
::
聚合
::
管理
::
24 随笔 :: 3 文章 :: 11 评论 :: 0 Trackbacks
<
2007年9月
>
日
一
二
三
四
五
六
26
27
28
29
30
31
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
1
2
3
4
5
6
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(4)
给我留言
查看公开留言
查看私人留言
随笔档案
2008年12月 (3)
2008年11月 (9)
2008年7月 (1)
2008年5月 (1)
2007年9月 (10)
文章档案
2011年3月 (1)
2008年11月 (1)
2007年12月 (1)
相册
个人影集
好友链接
我的C#博管
我的百度博客
搜索
最新评论
1. re: j2me模拟短信
我同意
--15170987588
2. re: 求助(边位仁兄有pointbase数据库的,麻烦传一份给我,急)
评论内容较长,点击标题查看
--ufo
3. re: MathLab使用
看不明白
--天涯浪子
4. re: MathLab使用[未登录]
请问要表示以(-0.5)为底的指数要怎么表示啊
--小小
5. re: MathLab使用
快速入门,方便大家...谢谢..
--292939760
阅读排行榜
1. 第四章 管理信息系统规划与开发方法(6117)
2. MathLab使用(2239)
3. 数学建模公车表(1722)
4. 数学建模公车表二(985)
5. 数学建模地铁信息(963)
评论排行榜
1. MathLab使用(3)
2. 数学建模公车表(3)
3. 数学建模地铁信息(2)
4. 数学建模公车表二(1)
5. 求助(边位仁兄有pointbase数据库的,麻烦传一份给我,急)(1)
看来大家也等急了,那我就暂发一点还有一点没完成(如何将Textbox里的文字写到文本文件中,希望会的朋友给我一点帮助,谢谢)
/**/
/*
* TextBoxTest.java
*
* Created on 2007年9月9日, 下午12:28
*/
import
java.io.ByteArrayOutputStream;
import
java.io.IOException;
import
java.io.InputStream;
import
javax.microedition.midlet.
*
;
import
javax.microedition.lcdui.
*
;
/** */
/**
*
*
@author
Administrator
*
@version
*/
public
class
TextBoxTest
extends
MIDlet
implements
javax.microedition.lcdui.CommandListener,javax.microedition.lcdui.ItemStateListener
{
private
Form form;
private
Display display;
private
TextBox textbox;
private
Command exitCmd;
private
Command backCmd;
private
Command menuCmd;
private
Command copyCmd;
private
Command cutCmd;
private
Command selectCmd;
private
Command pasteCmd;
private
Command saveCmd;
private
Command openCmd;
private
Command okCmd;
private
Command cancelCmd;
TextField tf;
Form tempform;
boolean
selectFlag
=
false
;
//
boolean firstClick=true;
String selectText
=
""
;
int
selectPosition,endPosition
=
0
;
public
TextBoxTest()
{
form
=
new
Form(
"
TextBox测度
"
);
display
=
Display.getDisplay(
this
);
tempform
=
new
Form(
""
);
textbox
=
new
TextBox(
"
TextBox
"
,
"
这是一个关于TextBox应用,实现在复制制,剪切功能
"
,
500
,TextField.ANY);
tf
=
new
javax.microedition.lcdui.TextField(
"
请输入文本文件名
"
,
""
,
20
,TextField.ANY);
exitCmd
=
new
Command(
"
退出
"
,Command.EXIT,
1
);
backCmd
=
new
Command(
"
退出
"
,Command.BACK,
1
);
selectCmd
=
new
Command(
"
选定
"
,Command.SCREEN,
1
);
copyCmd
=
new
Command(
"
复制
"
,Command.SCREEN,
1
);
cutCmd
=
new
Command(
"
剪切
"
,Command.SCREEN,
1
);
pasteCmd
=
new
Command(
"
粘贴
"
,Command.SCREEN,
1
);
saveCmd
=
new
Command(
"
保存
"
,Command.SCREEN,
1
);
openCmd
=
new
Command(
"
打开
"
,Command.SCREEN,
1
);
okCmd
=
new
Command(
"
确定
"
,Command.OK,
1
);
cancelCmd
=
new
Command(
"
取消
"
,Command.CANCEL,
1
);
textbox.addCommand(selectCmd);
textbox.addCommand(copyCmd);
textbox.addCommand(cutCmd);
textbox.addCommand(pasteCmd);
textbox.addCommand(saveCmd);
textbox.addCommand(openCmd);
textbox.addCommand(exitCmd);
textbox.addCommand(backCmd);
textbox.setCommandListener(
this
);
}
public
void
startApp()
{
display.setCurrent(textbox);
}
public
void
pauseApp()
{
}
public
void
destroyApp(
boolean
unconditional)
{
}
public
void
commandAction(Command command, Displayable displayable)
{
if
(command
==
selectCmd)
{
selectFlag
=
true
;
selectPosition
=
textbox.getCaretPosition();
}
else
if
((command
==
copyCmd)
&&
selectFlag)
{
int
temp
=
textbox.size();
char
[] chr
=
new
char
[temp];
textbox.getChars(chr);
if
(textbox.getCaretPosition()
>
selectPosition)
selectText
=
String.valueOf(chr,selectPosition,textbox.getCaretPosition()
-
selectPosition);
else
selectText
=
String.valueOf(chr,selectPosition,selectPosition
-
textbox.getCaretPosition());
selectFlag
=
false
;
}
else
if
(command
==
cutCmd)
{
int
temp
=
textbox.size();
char
[] chr
=
new
char
[temp];
textbox.getChars(chr);
selectText
=
String.valueOf(chr,selectPosition,textbox.getCaretPosition()
-
selectPosition);
if
(textbox.getCaretPosition()
>
selectPosition)
textbox.delete(selectPosition,textbox.getCaretPosition()
-
selectPosition);
else
textbox.delete(selectPosition,selectPosition
-
textbox.getCaretPosition());
selectFlag
=
false
;
}
else
if
(command
==
exitCmd)
{
destroyApp(
false
);
notifyDestroyed();
}
else
if
(selectText.length()
>
0
&&
command
==
pasteCmd)
{
/**/
/*
the first way
*/
//
textbox.insert(selectText,textbox.getCaretPosition());
/**/
/*
the second way
*/
char
[] chr
=
new
char
[selectText.length()];
selectText.getChars(
0
,selectText.length(),chr,
0
);
textbox.insert(chr,
0
,selectText.length(),textbox.getCaretPosition());
}
else
if
(command
==
saveCmd)
{
tempform.append(tf);
display.setCurrent(tempform);
tempform.addCommand(okCmd);
tempform.addCommand(cancelCmd);
tempform.setCommandListener(
this
);
}
else
if
(command
==
openCmd)
{
tempform.append(tf);
display.setCurrent(tempform);
tempform.addCommand(okCmd);
tempform.addCommand(cancelCmd);
tempform.setCommandListener(
this
);
}
else
if
(command
==
okCmd)
{
textbox.setString(myReadLine (tf.getString()));
display.setCurrent(textbox);
}
else
if
(command
==
cancelCmd)
{
display.setCurrent(textbox);
}
if
(command
==
backCmd)
{
destroyApp(
false
);
notifyDestroyed();
}
}
public
void
itemStateChanged(Item item)
{
}
private
String myReadLine (String testFileName)
{
InputStream in
=
this
.getClass().getResourceAsStream(testFileName);
ByteArrayOutputStream s;
s
=
new
ByteArrayOutputStream();
try
{
int
ch
=
0
;
ch
=
in.read();
while
( ch
!=
-
1
)
{
s.write( ch );
ch
=
in.read();
}
in.close();
}
catch
(IOException ioe)
{
System.out.println(ioe.toString());
}
String str
=
s.toString();
try
{
s.close();
}
catch
(IOException ioe)
{
System.out.println(ioe.toString());
}
return
str.trim();
}
}
张生工作室
posted on 2007-09-09 21:33
张生工作室
阅读(366)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
博客园最新博文
博问
管理
Powered by:
语源科技BlogJava
Copyright © 张生工作室