×

Discussion Board

Results 1 to 5 of 5

Thread: Learning J2ME

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    7

    Learning J2ME

    I'm new to J2ME.
    My work requires to run images on cellphones or mobiles unites, specially in nokia series 40.

    How can you paint or load images to a Canvas with exit buttons bellow?

    If you guys can give me a really simple sample codes for this.

    If it is also possible if you tell how to run these codes in Nokia Developer Suite for J2ME.

    Thanks for any helpl.

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    How can you paint or load images to a Canvas with exit buttons bellow?
    Extend com.nokia.mid.ui.FullCanvas instead of the Canvas.

    shmoove

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    7
    thanks shmoove.

    I am not pretty sure what is wrong with this code.
    It has no bugs what so ever but it does not display the image.
    Any suggestions?

    package PhoneImage;

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

    public class PhoneImage extends MIDlet implements CommandListener, ItemStateListener
    {
    private Command exitCommand;
    private Display display;

    Form displayForm;
    public Image image;

    public PhoneImage()
    {
    display = Display.getDisplay(this);
    exitCommand = new Command("Exit", Command.SCREEN, 1);

    try
    {
    image = Image.createImage("/icon.png");
    }

    catch (java.io.IOException ioExc)
    {
    ioExc.printStackTrace();
    }
    }

    public void startApp()
    {
    displayForm = new Form("Image");
    displayForm.append(new ImageItem("Default Layout", image, ImageItem.LAYOUT_DEFAULT, "Image Cannot be shown"));
    displayForm.addCommand(exitCommand);
    displayForm.setCommandListener(this);
    displayForm.setItemStateListener(this);
    display.setCurrent(displayForm);
    }

    public void itemStateChanged(Item item)
    {

    }

    public void pauseApp() { }

    public void destroyApp (boolean unconditional) { }

    public void commandAction (Command c, Displayable s)
    {
    if (c == exitCommand)
    {
    destroyApp(false);
    notifyDestroyed();
    }
    }
    }

  4. #4
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    The code looks OK. It probably isn't finding the image. Where exactly it can find it depends on teh development environment you're using. With some environments you would have to put the image in a "res" folder, with other inside the "src" folder, etc.
    Try moving it around to different folders, and playing with the path you use in createImage(), to see if this is the problem.
    Are you getting any exceptions when loading the image?

    [edit]
    By the way, you are not using neither Canvas not FullCanvas, so you definitely won't be getting a full screen display.
    [/edit]
    Last edited by shmoove; 2003-09-04 at 11:12.

  5. #5
    Registered User
    Join Date
    Sep 2003
    Posts
    7
    Thanks shmoove its been a great help.

    When I shift to J2ME from J2SE it was a whole new different ball game.

    I still don't know how to use that Canvas and FullCanvas.

    I really like to learn them. I already read a few eBooks on it but still I really want a very short sample code just do display and image using that Canvas and FullCanvas.

    This is why I still use the Form to display the image.


    Oh yes I need to know how the folders are reconstructed. I want them to be organized and put the on a separate folder, my personal folder.

    I'm just new to this I hope you guys don't mind.
    Last edited by ggbuid; 2003-09-05 at 02:56.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×