简体   繁体   中英

I am unable to draw image on Canvas in J2ME

I am try to load image on Canvas but it giving java.io.IOException exception . I don't know in which folder i have to put image. but right now i am putting image in F :\\New Folder\\DrawImage\\src\\Waterfall.png. i am using netbean editor for coding. reference code from here

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);
        }   
    }  
}

}

you need to make new folder at project folder and rename as rsc and copy and paste image in this folder. after that you need to go project properties and click on Build -> Libraries and Resources on that window you find Add Folder button click on that button locate you rsc folder and click ok. then run your project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM