Hey everybody
Im creating a MIDlet that should display an image.
But I get a l java.io.IOException.....
I've placed the picture test_j2me.png in the folder where all my files are.
My code looks like this :
public class Board extends Canvas implements CommandListener
{
private Game the_game;
public Graphics g;
public Image image;
private Command BACK = new Command("Back",Command.BACK,0);
//private Command EXIT = new Command("Exit",Command.EXIT,0);
private Command CLEAR = new Command("Clear",Command.OK,1);
private Display display;
private Displayable currentDisplayable;
private static final int WHITE = 0x00FFFFFF;
private static final int RED = 0x00FF0000;
public Board(Game the_game)
{
// There must be a call to super because this is the Canvas.class no arg constructor
super();
addCommand(BACK);
//addCommand(EXIT);
addCommand(CLEAR);
setCommandListener(this);
// This lines parses the instance of Game to the var the_game
// The instance of Game, instance_Game, is parsed to Board() - no arg constr - in Game.startApp()
this.the_game= the_game;
try
{
image = Image.createImage("C:/Documents and Settings/Christian V Petersen/JavaApplication5/src/BackG/test_j2me.png");
//
}
catch (IOException ioe)
{
System.out.println(ioe.getMessage());
ioe.printStackTrace();
}
}
public void commandAction(Command c, Displayable d)
{
if(c==BACK)
{
the_game.display.setCurrent(the_game.playMenu);
}
else if(c==CLEAR)
{
}
}
// this func is used to clear the Canvas
public void clear (Graphics g)
{
int clipX = g.getClipX();
int clipY = g.getClipY();
int clipH = g.getClipHeight();
int clipW = g.getClipWidth();
int color= g.getColor();
g.setColor(WHITE);
g.fillRect(clipX,clipY,clipW,clipH);
g.setColor(color);
}
public void paint(Graphics g)
{
//graphics
clear(g);
g.drawImage(image,0,0,Graphics.TOP|Graphics.LEFT);
}
}
Any help is fine
Thanks
CVP

Reply With Quote

