×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    How to load an image in my application

    Dear all,
    I know how to program in java. but dont have much idea about J2ME. i want a quick start thats why before going through detail, i want to develop a small application which would load an image (jpg or png) on the screen. i have been trying several times and looked at several forum posts here, but unfortunately i could not b succeed yet. would you please help me providing a small piece of code and step by step instructions!!!! please please please!!!
    u can send email to me too (golam.kaosar@gmail.com)

    thanks a lot.

  2. #2
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Mumbai
    Posts
    84

    Re: How to load an image in my application

    Hi golam.kaosar,

    check the javax.microedition.lcdui.Image class.
    this is javadoc for it....

    http://www.j2medev.com/api/midp/java...use/Image.html

    this is the way you put an image into your midlet

    Image b;
    b.createImage("image.png");
    With Regards,
    Mitesh Manani
    http://getpass.netfirms.com

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Re: How to load an image in my application

    dear,
    thanks a lot for quick reply. i already saw these classes. but i tried in several ways and did not get success. now i m confused about the whole process. therefore an example program (code) would be the best remedy for this problem. if u have such example, please let me know.
    thanks again.

  4. #4
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Mumbai
    Posts
    84

    Re: How to load an image in my application

    copy paste your part of the code so that i can make out the mistake that your making. try to do it yourself rather than getting the readymade code...
    You will learn better.
    With Regards,
    Mitesh Manani
    http://getpass.netfirms.com

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Re: How to load an image in my application

    here is the code:
    import javax.microedition.lcdui.*;
    import javax.microedition.lcdui.game.*;
    import java.io.*;
    public class ImageTest extends Canvas implements Runnable{
    private Image image;
    private int x;
    private int y;
    private TiledLayer layer;
    public ImageTest(String imageName)
    throws ApplicationException {
    try{
    image=Image.createImage("/image1.png");
    layer=new TiledLayer(7,7,image,20,20);
    x=(getWidth()-layer.getHeight())/2;
    y=(getHeight()-layer.getWidth())/2;
    layer.setPosition(x,y);
    }catch (IOException e){
    throw new Exception("Unable to create Image");
    }
    }
    public void paint(Graphics g){
    layer.paint(g);
    }
    public void run(){
    int n=0;
    while(n<=21){
    for(int i=0;i<7;i++){
    for(int j=0;j<7;j++){
    layer.setCell(i,j,(i+1)+n+(j*28));
    }
    }
    repaint();
    try{
    Thread.sleep(100);
    }catch(InterruptedException ie){}
    n++;
    }
    }
    }

    here the constructor has an argument. i dont know when and how the argument should be sent. also i dont know where the image file should be located. if i run this program following error occurs:
    Project "ImageTest" loaded
    Project settings saved
    Building "ImageTest"
    C:\java\WTK\apps\ImageTest\src\ImageTest.java:10: cannot find symbol
    symbol : class ApplicationException
    location: class ImageTest
    throws ApplicationException {
    ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    Build failed

    i am using java wireless toolkit
    i really appreciate and thank you for your kind and prompt reply.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    369

    Re: How to load an image in my application

    your error isnt related to loading an image nor even to j2me
    if u know java then it should be easy for u
    it says it cant find the class ApplicationException
    u declare the constructor to throw "ApplicationException" which is not a class or not in the src folder or the class-path
    i think u ment "throws Exception"
    since later on u do throw an Exception and nothing else


    p.s
    STOP SPAMMING your problem on all open threads
    thread jacking is not nice or will help u
    open one thread and wait for assistance

  7. #7
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Re: How to load an image in my application

    can u please give me a piece of code which would load an image file as the background of the application?
    thanks

  8. #8
    Regular Contributor
    Join Date
    Dec 2006
    Location
    Mumbai
    Posts
    84

    Re: How to load an image in my application

    make sure all the images are in the res folder of your toolkit.
    With Regards,
    Mitesh Manani
    http://getpass.netfirms.com

  9. #9
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Re: How to load an image in my application

    yes the image is there. i tried with the full path name too. i appreciate ur help. can i get your email address so that we could have more prompt communication.
    thanks a lot

Similar Threads

  1. Replies: 1
    Last Post: 2006-11-15, 07:03
  2. Load image from MBM file
    By palak_shah_23 in forum Symbian User Interface
    Replies: 17
    Last Post: 2006-11-04, 13:36
  3. How to load application in N80?
    By shiloliu in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-08-09, 11:19
  4. Can I install my application software into an image phone?
    By huangtx2004 in forum General Development Questions
    Replies: 3
    Last Post: 2004-08-23, 04:41
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

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