zoukankan
html css js c++ java
在手机上显示图片
/**/
/*
* 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();
}
}
}
效果:
查看全文
相关阅读:
linux 系统tar文件压缩打包命令
linux如何查看所有的用户和组信息?
go语言之行--golang操作redis、mysql大全
Redis集群的5种使用方式,各自优缺点分析
docker-compose搭建redis哨兵集群
windows版 navicat_15.0.18 安装
redis aof数据持久化
redis rdb数据持久化
03.redis 事务
02 redis 三种特殊的数据类型
原文地址:https://www.cnblogs.com/Dreamfly/p/388529.html
最新文章
SSH登录服务器报ECDSA host key "ip地址" for has changed and you have requested strict checking错误
Nginx日志切割
实现 nginx-https 访问得步骤过程
第18周作业
企业LVS实战案例之LVS-DR模式单网段案例
第17周作业
第16周作业
自签名证书和CA证书的区别
Linux面试之服务器安全
移动零
热门文章
数字转字符串
图片压缩、裁剪
requestAnimationFrame
多维数组最深层级
填充函数
js执行机制
myChunk
Babel原理
Base64原理及应用
golang计时器
Copyright © 2011-2022 走看看