そうです><
ただPC上でいくつかプロジェクトを作ったことがあるのですが
あるプロジェクトだけデバック環境で動くのに
吐き出されたファイルをPC上でクリックすると画像がないんです・・・
以下ソースです。
game.java
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
//(本体)
public class game extends MIDlet {
//コンストラクタ
public game() {
//キャンバスの指定
KeyCanvas c = new KeyCanvas();
Display.getDisplay(this).setCurrent(c);
//スレッドの実行
(new Thread(c)).start();
}
//アプリの開始
public void startApp() {
}
//アプリの一時停止
public void pauseApp() {
}
//アプリの終了
public void destroyApp(boolean flag) {
}
}
////////////////////////
gameCanvas.java
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.util.*;
//キー入力の処理(キャンバス)
class KeyCanvas extends GameCanvas
implements Runnable, CommandListener
{
private int keyEvent = -999; //キーイベント
private int keyState; //キー状態
private Command[/url] command = new Command[2];//コマンド
int SelPx = 96;
int SelPy = 96;
int[/url][/url] MapArray = {
{0,0,0,0,0},
{0,1,2,1,0},
{0,2,2,2,0},
{0,1,2,1,0},
{0,0,0,0,0}
};
//コンストラクタ
KeyCanvas()
{
//キーイベントの抑制
super(false);
}
//実行
public void run()
{
//グラフィックスの取得
Graphics g = getGraphics();
//画像ファイルの読み込み
Image Moon = null;
Image Sun = null;
Image Select = null;
try
{
Moon = Image.createImage("/tuki.png");
Sun = Image.createImage("/taiyo.png");
Select = Image.createImage("/select.png");
}
catch (Exception e)
{
System.out.println(e.toString());
}
//コマンドの生成
command[0] = new Command("速", Command.SCREEN, 0);
command[1] = new Command("遅", Command.SCREEN, 1);
//コマンドの追加
addCommand(command[0]);
addCommand(command[1]);
//コマンドリスナーの指定
setCommandListener(this);
while (true)
{
//キーイベントの処理
if (keyEvent == FIRE)
{
int x = SelPx / 48;
int y = SelPy / 48;
// ↑
if (MapArray[y - 1][x] == 1)
{
MapArray[y - 1][x] = 2;
}
else if (MapArray[y - 1][x] == 2)
{
MapArray[y - 1][x] = 1;
}
// ←
if (MapArray[y][x-1] == 1)
{
MapArray[y][x-1] = 2;
}
else if (MapArray[y][x-1] == 2)
{
MapArray[y][x-1] = 1;
}
// ×
if (MapArray[y][x] == 1)
{
MapArray[y][x] = 2;
}
else if (MapArray[y][x] == 2)
{
MapArray[y][x] = 1;
}
// →
if (MapArray[y][x+1] == 1)
{
MapArray[y][x+1] = 2;
}
else if (MapArray[y][x+1] == 2)
{
MapArray[y][x+1] = 1;
}
// ↓
if (MapArray[y+1][x] == 1)
{
MapArray[y+1][x] = 2;
}
else if (MapArray[y+1][x] == 2)
{
MapArray[y+1][x] = 1;
}
}
if (keyEvent == UP) SelPy -= 48;//上キー
if (keyEvent == DOWN) SelPy += 48;//下キー
if (keyEvent == LEFT) SelPx -= 48;//左キー
if (keyEvent == RIGHT) SelPx += 48;//右キー
keyEvent = -999;
//キー状態の処理
/*
keyState = getKeyStates();
// if ((UP_PRESSED & keyState) != 0) SelPy -= 48;//上キー
if ((DOWN_PRESSED & keyState) != 0) SelPy += 48;//下キー
if ((LEFT_PRESSED & keyState) != 0) SelPx -= 48;//左キー
if ((RIGHT_PRESSED & keyState) != 0) SelPx += 48;//右キー
*/
if (SelPx < 48)
{
SelPx = 48;
}
else if (SelPx > 48 * 3)
{
SelPx = 48 * 3;
}
if (SelPy < 48)
{
SelPy = 48;
}else if(SelPy > 48*3){
SelPy = 48 * 3;
}
//描画
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5; j++)
{
if (MapArray[j] == 1)
{
g.drawImage(Moon, j*48, i*48, Graphics.LEFT | Graphics.TOP);
}
else if (MapArray[j] == 2)
{
g.drawImage(Sun, j * 48, i * 48, Graphics.LEFT | Graphics.TOP);
}
}
}
g.drawImage(Select, SelPx, SelPy, Graphics.LEFT | Graphics.TOP);
flushGraphics();
//スリープ
try
{
Thread.sleep(50);
}
catch (Exception e)
{
}
}
}
//キープレスイベント
public void keyPressed(int keyCode)
{
if (keyCode == 0) return;
switch (getGameAction(keyCode))
{
case FIRE:
keyEvent = FIRE;
break;//選択キー
case UP:
keyEvent = UP;
break;//選択キー
case DOWN:
keyEvent = DOWN;
break;//選択キー
case RIGHT:
keyEvent = RIGHT;
break;//選択キー
case LEFT:
keyEvent = LEFT;
break;//選択キー
}
}
//コマンドイベント
public void commandAction(Command c, Displayable disp)
{
/*
if (c == command[0]) speed = 10;
if (c == command[1]) speed = 5;
*/
repaint();
}
}
//////////
画像はresに入っております。
png三枚 それぞれ48*48