Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Java Technology : Education - online courses
J2ME: Step by step
Download tutorial zip fileView letter-sized PDF fileView A4-sized PDF fileE-mail this tutorial to a friend
Main menuSection menuGive feedback on this tutorialPreviousNext
8. Development using KJava GUI components
  


HelloWorld -- complete code listing page 4 of 6


Following is the complete code sample for the HelloWorld application for a Palm device:


      import com.sun.kjava.Button;
      import com.sun.kjava.Graphics;
      import com.sun.kjava.Spotlet;

      /**
       * Simple demonstration, "Hello World" program. Note that Spotlet is
       * the class that provides callbacks for event handling.
       */
      public class HelloWorld extends Spotlet
      {
         /** Stores a reference to the "Exit" button. */
         private static Button exitButton;

         /**
          * Main entry point for this program.
          */
         public static void main(String[] args)
         {
            (new HelloWorld()).register(NO_EVENT_OPTIONS);
         }

         /**
          * Constructor: draws the screen.
          */
         public HelloWorld()
         {
            // Create (initially invisible) the "Exit" button
            exitButton = new Button("Exit",70,145);

            // Get a reference to the graphics object;
            // i.e. the drawable screen
            Graphics g = Graphics.getGraphics();
            g.clearScreen();

            // Draw the text, "Hello World!" somewhere near the center
            g.drawString("Hello World!", 55, 45, g.PLAIN);

            // Draw the "Exit" button
            exitButton.paint();
         }

         /**
          * Handle a pen down event.
          */
         public void penDown(int x, int y)
         {
            // If the "Exit" button was pressed, end this application
            if (exitButton.pressed(x,y))
              System.exit(0);
         }
      }

Main menuSection menuGive feedback on this tutorialPreviousNext
PrivacyLegalContact