Sabado, Enero 26, 2013

Connecting the Canvas to the MIDlet.


Connecting the Canvas to the MIDlet.

Since the entry class of any MIDlet must extend the MIDlet class it cannot extend the Canvas class we just created (no multiple inheritence in Java).
We need a MIDletimplementor class like the one below…
HelloWorld.java
importjavax.microedition.lcdui.Display;
importjavax.microedition.midlet.MIDlet;
importjavax.microedition.midlet.MIDletStateChangeException;

public class HelloWorld extends MIDlet {

        publicHelloWorld() {

        }

        protected void destroyApp(boolean conditional)
                       throwsMIDletStateChangeException {

        }

        protected void pauseApp() {

        }

        public void startApp() throws MIDletStateChangeException {

               Display.getDisplay(this).setCurrent(new HelloWorldCanvas());
        }
}
To recap, our entry class HelloWorld has its start method executed which sets our Canvas class HelloWorldCanvas to the currently displayed canvas (a MIDlet can have more than one Canvas). It then tells the canvas to begin drawing itself.

Walang komento:

Mag-post ng isang Komento