⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 highlevelevent.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
package com.j2medev.chapter3;

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

public class HighlevelEvent extends MIDlet implements CommandListener,ItemStateListener,ItemCommandListener {
    
    private Display display = null;
    private Form form = null;
    private TextField input = new TextField("input something:","",25,TextField.ANY);
    private StringItem button = new StringItem("","press me",StringItem.BUTTON);
    private Command exit = new Command("Exit",Command.EXIT,1); 
    private Command ok = new Command("Ok",Command.OK,2);
    
    public void startApp() {
        if(display == null){
            display = Display.getDisplay(this);
            form = new Form("high level event");
            form.append(input);
            form.append(button);
            form.addCommand(exit);
            button.addCommand(ok);
            //为StringItem注册ItemCommandListener
            button.setItemCommandListener(this);
            //为Form注册ItemStateListener和CommandListener
            form.setItemStateListener(this);
            form.setCommandListener(this);
        }
        display.setCurrent(form);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    //当exit被按下的时候,commandAction()方法被触发
    public void commandAction(Command cmd,Displayable displayable){
        if(cmd == exit){
            destroyApp(false);
            notifyDestroyed();
        }
    }
    //button上的Command被触发后 commandAction()方法被触发
    public void commandAction(Command cmd,Item item){
        if(item == button){
            if(cmd == ok){
                System.out.println("Button is pressed");
                display.vibrate(2000);
            }
        }

    }
    //input状态改变的时候,itemStateChanged方法被触发
    public void itemStateChanged(Item item){
        if(item == input){
            System.out.println("the input's state is changed");
            display.flashBacklight(2000);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -