HelloWorld -- 完整的代码清单(j2me代码)

作者在 2010-04-07 16:44:41 发布以下内容
HelloWorld -- 完整的代码清单HelloWorld -- 完整的代码清单 第 4 页(共 6 页)




以下便是 Palm 设备的 HelloWorld 应用程序的完整代码示例:


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

第 4 页(共 6 页)


以下便是 Palm 设备的 HelloWorld 应用程序的完整代码示例:

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); } }
默认分类 | 阅读 804 次
文章评论,共0条
游客请输入验证码
文章分类
文章归档
最新评论