写一个小代码 用J2ME显示一个图形

随便什么图把它显示出来越简单越好... 随便什么图 把它显示出来 越简单越好 展开
 我来答
snoopy83
2009-09-20 · TA获得超过618个赞
知道小有建树答主
回答量:528
采纳率:0%
帮助的人:234万
展开全部
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
* An example MIDlet with simple "Alert" UI component containing an Image.
*/
public class AlertImage extends MIDlet
{

private Display display; // The display for this MIDlet
private Alert myAlert = null;

public AlertImage() {
}

/**
* Call showAlert
*/
public void startApp() {

display = Display.getDisplay(this);
TextBox t = new TextBox("Hello MIDlet", "Hello J2MECamp!", 256, 0);
display.setCurrent(t);
System.out.println( "Gonna create Alert.." );
createAlert();
}

/**
* Puts up an Alert with an Image
*/
private void createAlert()
{
myAlert = new Alert("MIDlet Alert");
String[] alertString = { " Alert String" };
myAlert.setTimeout(Alert.FOREVER);
// Add an image to Alert
if (display.numColors() > 2)
{
String icon = (display.isColor()) ?"/JavaPowered-2.png" : "/JavaPowered-8.png";
try
{
Image image = Image.createImage( icon );
if (image != null)
{
myAlert.setImage(image);
System.out.println( "Image created and added to alert.. " );
}
else
{
System.out.println( "No Image created... " );
}
// Add string to Alert
for ( int i = 0; i < alertString.length; i++ ) {
myAlert.setString( alertString[i] );
}
if ( myAlert != null ) {
display.setCurrent( myAlert );
}
}
catch( Exception e ) {
System.out.println( "Exception in CreateImage() " );
}
}
}

/**
* Pause is a no-op since there are no background activities or
* record stores that need to be closed.
*/
public void pauseApp() {
}

/**
* Destroy must cleanup everything not handled by the garbage collector.
* In this case there is nothing to cleanup.
*/
public void destroyApp(boolean unconditional) {
}

}

以上代码放在src中的java文件中,与src并列的res文件夹中放置JavaPowered-2.png 和JavaPowered-8.png 两个图片
cho618
2009-09-20
知道答主
回答量:53
采纳率:0%
帮助的人:30.9万
展开全部
拿起画笔,g.drawImage就是
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式