Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » 移动互联网  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 求助:程序中用Alert ,Image显示图象无效果,
860123





发贴: 2
积分: 0
于 2008-01-25 12:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如上,程序运行正常,但本来应该显示图片的位置一片空白,我的图片放的位置没问题,但就是显示不出来,源代码如下:

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;

public class LostInForest extends MIDlet implements CommandListener {//实现接口CommandListener
 private Display display;
private Canvas canvas;
private Command exitCmd;//定义返回键
private Image anImage;
private Alert cAlert;
MenuScreen menuScreen=new MenuScreen();

Alert aAlert=new Alert("游戏方法","进入游戏后,按↑↓←→控制小精灵移动的方向"+
     "碰到火堆将扣去一点生命,碰到水滴增加一点生"+
     "命,生命值没有上限,当扣完生命值时,主角将死"+
     "亡,当主角到达出口时,将逃脱森林,胜利",null,AlertType.INFO);
Alert bAlert=new Alert("制作小组","-_-#",null,AlertType.INFO);



public LostInForest(){
  
   try{
      anImage=Image.createImage("c:/0027.png");
     }
     
     catch(IOException ioe){
       ioe.printStackTrace();
     }
cAlert=new Alert("Welcome",null,anImage ,AlertType.CONFIRMATION);
  exitCmd=new Command("返回",Command.EXIT,2);
  //将Alert定义为永久模式
  aAlert.setTimeout(Alert.FOREVER);
  bAlert.setTimeout(Alert.FOREVER);
  
  //将按钮添加到Alert上
  aAlert.addCommand(exitCmd);
  bAlert.addCommand(exitCmd);
  //注册事件监听器
  aAlert.setCommandListener(this);
  bAlert.setCommandListener(this);
}




public void startApp ( )
{
  canvas=new MenuScreen();
  cAlert.setTimeout(4000);
  display=Display.getDisplay(this);
  display.setCurrent(cAlert, canvas);
  
}
  
public void pauseApp(){
  
}
public void destroyApp(boolean b)
{
  
}
//实现commandAction方法,处理高级事件程序
public void commandAction(Command cmd,Displayable dis){
  if(cmd==exitCmd){
    display.setCurrent(menuScreen);
  }
}
//定义一个继承类Canvas类的MenuScreen类
class MenuScreen extends Canvas implements Runnable{
  //获得LowFont字体长度
  final Font lowFont=Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_MEDIUM);
  //获得highFont字体的长度
  final Font highFont=Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_LARGE);
  //设置字体颜色
  final int lowColor=0x007FFF00;
  final int highColor=0x0000BFFF ;
  final int highBGColor=0x00AAAAAA;
  int width;//屏幕的宽
  int height;//屏幕的高
  //菜单起始位置的高度
  int startHeight;
  //整个菜单的高度
  int menuHeight;
  //菜单选项之间的高度
  final int spacing=highFont.getHeight()/2;
  //菜单内容
  final String[] mainMenu={"开始游戏","游戏方法","制作小组","退出"};
  //数组下标
  int menuldx;
  //定义线程
  Thread menuThread;
  
public MenuScreen(){
  width=getWidth();
  height=getHeight();
  menuHeight=(highFont.getHeight()*mainMenu.length)+((mainMenu.length-1)*spacing);
  startHeight=(height-menuHeight)/2;
  menuldx=0;
  //创建线程,其this指向的是menuScreen对象
  menuThread=new Thread(this);
  //启动线程
  menuThread.start();
}
//实现run(),实现重画***能
public void run(){
  while(true){
    repaint();
  }
}
//实现paint(Graphics g)方法,在画布上画上一些对象
public void paint(Graphics g){
  g.setColor(0X00FFFF00 );//背景颜色
  g.fillRect(0,0,width,height);
//定义字体颜色大小和内容
  
  g.setColor(255,00,00);
  g.setFont(Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_LARGE));
  Font labell=Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_LARGE);
  g.drawString("迷失森林",62,8,g.TOP|g.LEFT);
  
  g.setColor(255,00,00);
  g.setFont(Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_LARGE));
  g.drawString("Lost in the forest 1.0",0,24,g.TOP|g.LEFT);
  
  
  g.setColor(255,00,00);
  g.setFont(Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
  g.drawString( " 邮箱地址保密",25,145,g.LEFT|g.TOP);
  
  g.setColor(255,00,00);
  g.setFont(Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
  g.drawString( " 所有权属于作者",30,160,g.LEFT|g.TOP);
  
//将选中的菜单变为大号字体
  for(int i=0;i<mainMenu.length;i++){
    if(i==menuldx){
      g.setColor(highBGColor);
      g.fillRect(0,startHeight+(i*highFont.getHeight())+spacing,width,highFont.getHeight());
g.setFont(highFont);
g.setColor(highColor);
g.drawString(mainMenu[i],(width-highFont.stringWidth(mainMenu[i]))/2,startHeight+(i*highFont.getHeight())+spacing,20);
}
    else{
      g.setFont(lowFont);
      g.setColor(lowColor);
      g.drawString(mainMenu[i],(width-lowFont.stringWidth(mainMenu[i]))/2,startHeight+(i*highFont.getHeight())+spacing,20);
      
    }
  }
}

//定义低级时间处理keyPressed(),获得按键所对应的事件
protected void keyPressed(int code){
//如果单击向上键,则菜单上移
  if(getGameAction(code)==Canvas.UP&&menuldx-1>=0){
    menuldx--;
  }
//如果单击向下键,则菜单下移
  else if (getGameAction(code)==Canvas.DOWN&&menuldx+1<mainMenu.length){
    menuldx++;
  }
  //如果单击"FIRE"键,则程序进入相应的***能模块
  if(getGameAction(code)==Canvas.FIRE){
    if(mainMenu[menuldx]=="开始游戏"){
      
    }
    else if(mainMenu[menuldx]=="游戏方法"){
      display.setCurrent(aAlert);
    }
    else if(mainMenu[menuldx]=="制作小组"){
      display.setCurrent(bAlert);
      
    }
    else if(mainMenu[menuldx]=="退出"){
      notifyDestroyed();
    }
  }
}

}
SadSadSad




flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923