Implementing the HelloWorldMIDlet

A MIDlet that will display a simple SVG graphic of a "smiley face" using the SvgCanvas1 to render it.

  1. Create the HelloWorldMIDlet class file.

  2. Import the required classes and assign this class to the com.nokia.midp.examples.svg package.

    /* Copyright © 2006 Nokia. */
    package com.nokia.midp.examples.svg;
    
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
  3. Set HelloWorldMIDlet to extend midlet and to implement CommandListener.

     /**
     * Simple midlet that displays a static SVG file.
     */
     public class HelloWorldMIDlet extends MIDlet implements CommandListener {
  4. Write the below code to construct the Midlet. Create a new SvgCanvas1 object for building the actual image.

    /**
    * Constructor.
    */
        public HelloWorldMIDlet() {
        	
            // *** create the SVG canvas
            svgCanvas = new SvgCanvas1 (false);
            svgCanvas.setCommandListener(this);
            
    
    		  // *** grab a reference to the display
            display = Display.getDisplay(this);
            display.setCurrent(svgCanvas);
    

    Add Commands for exiting and zooming the image.

            
            // *** set up the midlet menu
            int hotKey = 0;
            
            cmZoomIn = new Command("Zoom In", Command.SCREEN, hotKey++);
            svgCanvas.addCommand(cmZoomIn);
            
            cmZoomOut = new Command("Zoom Out", Command.SCREEN, hotKey++);
            svgCanvas.addCommand(cmZoomOut);
    
            cmExit = new Command("Exit", Command.SCREEN, hotKey++);
            svgCanvas.addCommand(cmExit);
        }
  5. Add the following three required methods.

    	 /**
    	 * Required midlet method.
    	 */
        public void startApp() {
        }
    
    
    	 /**
    	 * Required midlet method.
    	 */
        public void pauseApp() {
        }
    
        
    	 /**
    	 * Required midlet method.
    	 */
        public void destroyApp(boolean unconditional) {
        }
  6. Add the Command actions for zoom and exit functions.

       public void commandAction(Command c, Displayable s) {
            if (c == cmExit) {
                destroyApp(false);
                notifyDestroyed();
            }   else if ( c == cmZoomIn ) {
                    svgCanvas.zoomIn();
            }   else if ( c == cmZoomOut ) {
                    svgCanvas.zoomOut();
            }
        }
    

    Initiate the private objects.

    
    	 /*
    	 * Private members
    	 */
    
        private Display display;
        private SvgCanvas1 svgCanvas;
    
        private Command cmExit;
        private Command cmZoomIn;
        private Command cmZoomOut;
    }