会员
众包
新闻
博问
闪存
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
无限精彩,DreamflyIT世界!
有一种执著叫坚持,有一种梦想叫超越!
导航
博客园
首页
新随笔
联系
订阅
管理
公告
在手机上显示图片
Posted on
2006-04-29 12:18
韦忠波
阅读(
364
) 评论(
0
)
编辑
收藏
举报
/**/
/*
* First.java
*
* Created on 2006年4月27日, 下午4:47
*/
import
javax.microedition.midlet.
*
;
import
java.io.ByteArrayOutputStream;
import
java.io.IOException;
import
java.io.InputStream;
import
javax.microedition.lcdui.
*
;
/** */
/**
*
*
@author
hero
*
@version
*/
public
class
First
extends
MIDlet
implements
CommandListener
{
private
Display display
=
null
;
private
Form mainForm
=
null
;
public
static
final
Command exitCommand
=
new
Command(
"
退出
"
,Command.OK,
1
);
public
void
startApp()
{
if
(display
==
null
)
{
display
=
Display.getDisplay(
this
);
}
mainForm
=
new
Form(
"
First
"
);
Image img
=
getImage(
"
d.png
"
);
//
注意图片格必须是png格式的
mainForm.append(img);
String text
=
""
;
try
{
text
=
getText(
"
xx.txt
"
);
//
可以显示文字的
}
catch
(IOException ex)
{
text
=
"
读取文本出错!
"
;
}
mainForm.append(
"
\n
"
+
text);
mainForm.addCommand(exitCommand);
mainForm.setCommandListener(
this
);
display.setCurrent(mainForm);
}
public
Image getImage(String name)
{
Image img
=
null
;
try
{
img
=
Image.createImage(
"
/res/images/
"
+
name);
//
注意图应该是png格式,且放在src的res下
System.out.println(img);
}
catch
(IOException ex)
{
System.out.println(
"
fERROR
"
);
ex.printStackTrace();
}
return
img;
}
private
String getText(String name)
throws
IOException
{
InputStream is
=
getClass().getResourceAsStream(
"
/res/text/
"
+
name);
if
(is
!=
null
)
{
ByteArrayOutputStream baos
=
new
ByteArrayOutputStream();
int
ch
=
0
;
while
((ch
=
is.read())
!=-
1
)
{
baos.write(ch);
}
byte
[] text
=
baos.toByteArray();
baos.close();
return
new
String (text,
"
UTF-8
"
);
}
else
{
return
null
;
}
}
public
void
pauseApp()
{
}
public
void
destroyApp(
boolean
unconditonal)
{
}
public
void
commandAction(Command c, Displayable d)
{
if
(c
==
exitCommand)
{
destroyApp(
false
);
notifyDestroyed();
}
}
}
效果:
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 韦忠波
Powered by .NET 8.0 on Kubernetes