Hi formers how are you?
I'm here again with very simple and stupid problem, That I'm in trouble in getting the image from res folder
Hoping good and brisk response from you guys
a bundle of thankx for all of you......
here is my source code I'm getting with....
THIS IS THE MAIN MIDlet
package imageeo;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* @author 031-bscs-08
*/
public class ImageMidlet extends MIDlet implements CommandListener{
private Image image = null;
private ImageClass canvasClass;
public ImageMidlet()
{
}
public void startApp()
{
canvasClass = new ImageClass();
canvasClass.addCommand(new Command("Exit", Command.EXIT, 0));
Display.getDisplay(this).setCurrent(canvasClass);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) { }
public void commandAction(Command c, Displayable d)
{
if(c.getCommandType() == Command.EXIT)
{
destroyApp(true);
notifyDestroyed();
}
}
}
AND HERE IS THE CANVAS CLASS
package imageeo;
import java.io.IOException;
import javax.microedition.lcdui.*;
/**
*
* @author 031-bscs-08
*/
public class ImageClass extends Canvas implements Runnable {
private Image image = null;
public ImageClass()
{
try {
// I think the lurks are here that are pushing my application down
this.image = Image.createImage("/res/Delete-icon.png");
new Thread(this).start();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void run()
{
while(true)
{
repaint();
synchronized(this)
{
try {
wait(50);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}
protected void paint(Graphics g)
{
g.setColor(0xffffff);
g.fillRect(0, 0, getWidth(), getHeight());
if(image != null){
g.drawImage(image, getWidth() / 2, getHeight() / 2, Graphics.HCENTER
| Graphics.VCENTER);
} else {
g.setColor(0x000000);
g.drawString("No image available", getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.BASELINE);
}
}
}

Reply With Quote


