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();
}
}
}
效果:
查看全文
相关阅读:
tidb3.2参数优化配置整个过程
tidb优化配置
mysql使用docker安装
mysql密码规则配置-配置为简单密码123456
goaccess日志分析器使用
c# printDialog不显示问题
short数组写进txt
txt文件存储问题
c# 调用c++dll二次总结
程序员代码开发的自测素养
原文地址:https://www.cnblogs.com/Dreamfly/p/388529.html
最新文章
不均匀材料的模拟
发现一个问题
代码可视化暂时效果
实现碰撞
一些重要的mel命令
selenium 操作cookie (cookie测试)
AutoIt 3.0 操作之初体验(第一个脚本hello world)
selenium 文件上传
selenium 下拉框处理
selenium 警告框处理 (弹窗处理)
热门文章
selenium 多窗口切换(windows)
selenium 多表单切换处理(iframe/frame)
seleniumu 3.0复选框操作(定位一组元素)
selenium 找不到元素 (显式等待 和隐式等待的区别)
selenium 3.0 键盘事件 +强制结束chromedriver进程代码
tidb的监控grafana通过nginx反向代理到外网
jenkins安装并使用nginx代理到外网访问
oracle用户密码过期处理,设置为永不过期
redis常用命令
tidb3.0.2使用 TiDB Ansible 扩容TiDB 集群的tikv节点
Copyright © 2011-2022 走看看