×

Discussion Board

Results 1 to 9 of 9

Thread: Adding Images

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    11

    Adding Images

    hi,

    Im new to J2ME and the forums, doing a college project having alot of difficulties.

    I have this command listener line:
    private Command exitCommand = new Command("Exit", Command.EXIT, 99);
    But what does the "99" refer to.

    The game is for a phone but how do you map the keys on a keypad (the specific phone is the Nokia 3510i, its a series 40).

    I`m having awful trouble with images i have this code but it doesn`t work:

    (inside the class)
    Image Image1;

    (inside a function)
    try { Image1=Image.createImage("/logo_PNG.png");
    }
    catch(Exception e)
    {
    message="error";
    }

    The program runs but never displays the iimage, the picture just never goes into Image1.

    Using the debug mode in JBuilder I get: Image1: javax.microedition.lcdui.Image = null

    Any help will be greatly appreciated

  2. #2
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429
    Hi...

    "99" referes to the priority of ur command!

    Check whether u have placed an image in the res folder!

    Also where are u trying to display the image?? in a form or in Canvas?? I Did not find any code to display the image in ur code
    ,,
    regards
    Gopal

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    11
    Trying to display the image in a canvas.

    Not sure what you mean by the re folder. the images currently is in the classes folder.

    found out that command.exit will map the exit button to what is "usually" the exit button on the particular phone. is this true

    If it is how do you address the number keys?

    Any help will be greatly appreciated
    thanks.

  4. #4
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429
    Hi...

    The Images should be in the resources folder(res).not in Classes folder; That may be the problem.

    And about EXIT:
    A command used for exiting from the application. When the user invokes this command, the implementation does not exit automatically. The application's commandAction will be called, and it should exit the application if it is appropriate to do so.
    Value 7 is assigned to EXIT.(plz check the API docs)

    There are a set of key codes for all keys like in series 40 LSK = -6,RSK =-7 and so on.....

    regards
    Gopal

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7
    I`m also doing a J2ME game.

    The game is in a package called game.

    I saved the image i`m using to the classes folder and this is the only place it works.I tried putting it in the following folders:

    J2ME_game\
    J2ME_game\res
    J2ME_game\classes\game

    But it doesn`t work from any of these, is there something you need to do so that it will see it in the res folder?
    will the way I have it affect the program when I build it into a Jar file?

  6. #6
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    It all depends on how you are building your applications. Most SDKs (like the WTK, NDS, many IDEs) have a "press a button for a complete build"-type option. Each of these build environments has a different way of packaging the application. The WTK just takes whatever is in the res folder and puts it in the root of the jar. Other environments might take files from other directories. You can set up your own build environment (using the command line, batch files, Ant, etc.) and do it in a way that is specific to you. Putting resources in the classes directory will usually work because this directory has to be included (or else you won't have much of an application), so it usually works. But some build scripts do a clean build by erasing the classes directory before compilation (oops, there go your resources!).

    So basically, the answer to the whole "where to put the images" dilemma is "it depends".

    A good idea is to get familiar with Ant (and the J2ME specific tasks in Antenna), so that you can easily set up a build script exactly how you want it. It might take a few hours to get acquainted with the system, but the result is that you have complete control over your builds so you know exactly what is happening and what files are going into your jars (you can even set it up so that by changing a property you can make builds that take resources from different places to create specific builds for specific phones).

    In the end you can always use any old zip utility to open up your jar and see exactly what files are in there and with what path they are stored.

    shmoove

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    11
    We are using JBuilder Mobile

    We seem to have got the image working it was placed in the wrong folder.

    We also got it moving around as well and got all the action listeners working too, still a long way to go but hopefully we can go from here.

    Thanks alot.

  8. #8
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,429
    Thankz shmoove!
    I thought images should only be in res folder...

    regards
    Gopal

  9. #9
    Registered User
    Join Date
    Feb 2005
    Posts
    5

    Re: Adding Images

    1. The Image is not found I guess, chk the path of the file
    2. Try other createImage methods
    3. You will have to do display.setCurrent and display it once you get he image correctly loaded.

    sample code:
    Display display = Display.getDisplay(this);

    Form form = new Form("Form Name");

    InputStream inputStream = getClass().getResourceAsStream("incredi2-thumb.jpg");
    System.out.println(inputStream.available());
    byte[] image = new byte[inputStream.available()];
    inputStream.read(image);
    Image image1 = DirectUtils.createImage(image,0,image.length);
    form.append(image1);
    display.setCurrent(form);
    Hope it helps;-)

    BTW - Do you know how to open a image so that the default option of open,save,delete,rename options(nokia 3120, or I guess avaiable in others as well as they are basic) are visible and subsequently trapped. if at all it is possible using j2me?
    -Praveen Acharya



    Originally posted by davewit13
    hi,

    Im new to J2ME and the forums, doing a college project having alot of difficulties.

    I have this command listener line:
    private Command exitCommand = new Command("Exit", Command.EXIT, 99);
    But what does the "99" refer to.

    The game is for a phone but how do you map the keys on a keypad (the specific phone is the Nokia 3510i, its a series 40).

    I`m having awful trouble with images i have this code but it doesn`t work:

    (inside the class)
    Image Image1;

    (inside a function)
    try { Image1=Image.createImage("/logo_PNG.png");
    }
    catch(Exception e)
    {
    message="error";
    }

    The program runs but never displays the iimage, the picture just never goes into Image1.

    Using the debug mode in JBuilder I get: Image1: javax.microedition.lcdui.Image = null

    Any help will be greatly appreciated

Posting Permissions

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