Question

I am trying to display a PNG image on blackberry device for OS 5.0 using J2ME MIDlet class instead of a blackberry RIMlet class. Can I use J2ME MIDlet instead of RIMlets? Would it be compatible with blackberry as blackberry do support J2ME? Can I get the image from it?

Was it helpful?

Solution

Its good to use Midlet with canvas to show on canvas because if you use Midlet with Form then its show image but its also showing the theme of mobile in background of form. If you use canvas you can use also background image for your front image. Thanks

OTHER TIPS

To display an image on the screen of a BlackBerry® device, create an Image object and populate it by calling the static Image.createImage() method. Provide the location of the image as a parameter.

refer display an PNG image using J2ME MIDlet classes on blackberry device

Can i use J2ME MIDlet instead of RIMlets...

YES, but there are certain advantages like mentioned here.

and if you want to go with MIDlet, here is an example using ImageItem,

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

public class ImageItemMIDlet extends MIDlet implements CommandListener{
  private Command exit;
  private ImageItem imageItem;
  private Image image;
  private Display display;
  private Form form;

  public ImageItemMIDlet(){
  try{
  image = Image.createImage("/yourImage.png");
  } catch (Exception e){ }
  imageItem = new ImageItem("This is the IMAGE_ITEM Application", 
  image, ImageItem.LAYOUT_DEFAULT, "image");
  }

  public void startApp(){
  form = new Form("ImageItem Example");
  display = Display.getDisplay(this);
  exit = new Command("Exit", Command.EXIT, 1);
  form.append(imageItem);
  form.addCommand(exit);
  form.setCommandListener(this);
  display.setCurrent(form);
  }

  public void pauseApp(){}

  public void destroyApp(boolean unconditional){
  notifyDestroyed();
  }

  public void commandAction(Command c, Displayable d){
  String label = c.getLabel();
  if(label.equals("Exit")){
  destroyApp(true);
  }
  }
} 

public class Midlet extends MIDlet {

public Display display;

public void startApp() {

    Canvas obj = new DrawImage();

    display = Display.getDisplay(this);
    display.setCurrent(obj);

}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}


public class DrawImage extends Canvas{

    int width = getWidth();
    int height = getHeight();

    protected void paint(Graphics g) {
        try {

            System.out.println("111111");
            Image image = Image.createImage("/Waterfall.png");
            if(image != null)
                g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
            else
                System.out.println("2222");
        } catch (IOException ex) {
            System.out.println(ex);
        }   
    }  
}   

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top