An example MIDlet with simple Hello text and an Exit command : 事件命令 « 基于J2ME « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » 基于J2ME » 事件命令屏幕截图 
An example MIDlet with simple Hello text and an Exit command
An example MIDlet with simple Hello text and an Exit command


/*
 *
 * Copyright (c) 2000 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 */

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * An example MIDlet with simple "Hello" text and an Exit command.
 * Refer to the startApp, pauseApp, and destroyApp
 * methods so see how each handles the requested transition.
 */
public class HelloCommandMIDlet extends MIDlet implements CommandListener {

  private Command exitCommand; // The exit command
  private Command okCommand; // The exit command
  private Command cancelCommand; // The exit command
  private Command nextCommand; // The exit command
  private Command backCommand; // The exit command
    private Display display;  // The display for this MIDlet

    public HelloCommandMIDlet() {
        display = Display.getDisplay(this);
       exitCommand = new Command("Exit", Command.EXIT, 2);
    }

    /**
     * Start up the Hello MIDlet by creating the TextBox and associating
     * the exit command and listener.
     */
    public void startApp() {
        TextBox t = new TextBox("Hello""Hello World!"2560);

        t.addCommand(exitCommand);
        t.setCommandListener(this);

        display.setCurrent(t);
    }

    /**
     * Pause is a no-op since there are no background activities or
     * record stores that need to be closed.
     */
    public void pauseApp() {
    }

    /**
     * Destroy must cleanup everything not handled by the garbage collector.
     * In this case there is nothing to cleanup.
     */
    public void destroyApp(boolean unconditional) {
    }

    /*
     * Respond to commands, including exit
     * On the exit command, cleanup and notify that the MIDlet has been destroyed.
     */
    public void commandAction(Command c, Displayable s) {
  if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
  
    }

}


           
       
Related examples in the same category
1. 简单的命令演示简单的命令演示
2. 命令命令
3. 各种事件各种事件
4. 命令,项目和事件处理命令,项目和事件处理
5. Api concepts Refer to the startApp pauseApp, and destroyAppApi concepts Refer to the startApp pauseApp, and destroyApp
6. 在线帮助
7. 第一个应用程序:简单的文字和一些命令第一个应用程序:简单的文字和一些命令
8. 许多命令许多命令
9. 绘图命令绘图命令
10. 捕获项目活动捕获项目活动
11. 访问命令访问命令
12. A quick sample of graphics, commands, and event handling.A quick sample of graphics,  commands, and event handling.
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.