This discussion is archived
0 Replies Latest reply: Apr 13, 2010 3:21 AM by 807581 RSS

Display of Custom Item in Emulator and Nokia Phone are different

807581 Newbie
Currently Being Moderated
I'm creating a Custom Item which will either display text or image depending on the parameter. I tried with both displaying of text and image on the emulator and it looks reasonably well. However, when i install in my Nokia 6210, the display is not the same. The longer text (more than 30 characters including space) appears to be truncated as the Nokia 6210's screen width seems to be smaller. Then, i increased the minimum height in my code and break the texts to 2 lines to be displayed. Again, it's displayed well in the emulator but on the phone, the 2 lines of texts are overlapping.

For image, i can position the image by changing the anchor of the image and x & y in g.drawImage. Again, it's displayed correctly on the emulator but it's not well aligned on the phone and the image looks to be smaller with the background rectangle of the Custom Item.

What i want to achieve is to display the texts or image well aligned horizontally and vertically in various J2ME devices. Can anyone give me some clues like what parameters to change or to take note?
Below are my code:
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

import java.io.*;
import java.lang.*;
import java.util.*;





public class BCItem extends CustomItem implements ItemCommandListener {

    private MyMidlet midlet;
    private String linkURL;
    private boolean isText;
    private String bannerText;
    private Image image;
    private final static Command CMD_OK = new Command("Visit Ads", Command.ITEM, 1);
    private String [] displayText;
    private String displayTextPart;
    private int displayableWidth;


    public BCItem (String title, MyMidlet midlet, String linkURL, boolean isText, String bannerText, Image image) {
        super(title);

        this.midlet = midlet;
        this.linkURL = linkURL;
        this.isText = isText;
        this.bannerText = bannerText;
        this.image = image;

        displayableWidth = midlet.getWidth();     


        setDefaultCommand(CMD_OK);
        setItemCommandListener(this);

    }

     public int getMinContentWidth(){
    return 240;
  }

  public int getMinContentHeight(){
    return 20;
  }

  public int getPrefContentWidth(int width){
    return displayableWidth;
  }

  public int getPrefContentHeight(int height){
    return getMinContentHeight();
  }

  public void paint(Graphics g, int w, int h){
      if (isText) {
          g.setColor(0x000000);
          g.setFont(Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_UNDERLINED, Font.SIZE_SMALL));

            g.drawString(bannerText,1, 1,
                   Graphics.LEFT| Graphics.TOP);

      }
      else {
           try {


            g.drawImage(image, getMinContentWidth()/2 + 20, 1, Graphics.RIGHT| Graphics.TOP  );
        }
        catch (Exception e) {
            e.printStackTrace();
        }
      }
  }
    
  public void commandAction(Command c, Item i) {
      if (c == CMD_OK) {

          try {
              System.out.println(linkURL + " visited");
              if (midlet.platformRequest(linkURL)) {
                  System.out.println(linkURL + " visited");
              }
          }
          catch (Exception e) {
              e.printStackTrace();
          }
      }
  }

 

}