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();
}
}
}
效果:
查看全文
相关阅读:
LeetCode_4——寻找两个有序数组的中位数
Java的CAS与ABA问题
跨域问题解决
解决git-for-windows官网下载速度慢的问题
Java对观察者模式的支持
Java动态代理
设计模式七大原则
UML中的类图关系
布隆过滤器(Bloom Filter)与Hash算法
Ubuntu16安装fabric1.4.4环境
原文地址:https://www.cnblogs.com/Dreamfly/p/388529.html
最新文章
js的增改删
第二章 虚拟机的软件及其安装
第一章 Linux操作系统及其历史介绍
B. Plus from Picture
E2. Three Blocks Palindrome (hard version)
B. Codeforces Subsequences
C. Even Picture
F. Spy-string
B
A
热门文章
D. Task On The Board
I
重写和重载
茶话途说
WebSocket
java面试——多线程与并发
java面试——计算机网络
小公司实习
SprinBoot易学难精
Java数据结构算法
Copyright © 2011-2022 走看看