I am creating an Application which displays an image in the Emulator ..It works fine in the Emulator but when i create a Jar file and test it in mobile its not displaying ...
I wont get any error message in Jar File... I am using Eclipse IDE and Sun Java Wireless Toolkit....
In Jar File we get only the Alert text and not the image...Please help me out..
I have tried Nokia s40 and s60 mobile phones ..
Here is the Code
package com;
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class AlertExample extends MIDlet implements CommandListener{
private Display display;
public Form form;
private Command ok,cancel,done;
private Image img, imge, img2;
private CanvasString canvas;
public AlertExample() {
form = new Form("Info Transmit");
cancel = new Command("Cancel", Command.CANCEL, 2);
ok = new Command("OK", Command.OK, 2);
canvas = new CanvasString();
try{
img = Image.createImage("/logo.jpg");
imge = Image.createImage("/alert.jpg");
img2 = Image.createImage("/Logo1.jpg");
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public void startApp() {
display = Display.getDisplay(this);
try{form.append(img);}catch(Exception e){}
canvas.addCommand(cancel);
canvas.addCommand(ok);
canvas.setCommandListener(this);
try
{
new Thread().run();
{
Alert success = new Alert("OK", "Alert Message Here!",img,AlertType.INFO);
success.setTimeout(5000);
success.setImage(img2);
display.setCurrent(success);
}
Thread.sleep(5000);
display.setCurrent(canvas);
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void showMsg(){
Alert success = new Alert("OK", "Alert Message Here!",
img2, AlertType.INFO);
success.setTimeout(5000);
success.setImage(img2);
display.setCurrent(success, form);
}
public void tryAgain() {
Alert error = new Alert("Cancel", "Alert Message Here!", imge, AlertType.INFO);
error.setTimeout(5000);
error.setImage(imge);
display.setCurrent(error, form);
}
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if(label.equals("Cancel")) {
tryAgain();
} else if(label.equals("OK")) {
showMsg();
}
}
}
class CanvasString extends Canvas {
boolean string = true;
void toggleString() {
string = !string;
repaint();
}
public void paint(Graphics g) {
g.setColor(0xccff66);
g.fillRect(0, 0, getWidth(), getHeight());
if(string) {
Font font = g.getFont();
int fontHeight = font.getHeight();
int fontWidth = font.stringWidth("This is the Toggle Message");
g.setColor(223, 0, 112);
g.setFont(font);
}
}

Reply With Quote


