/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package hello;

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

/**
 * @author Administrator ItemStateListener 事件处理
 */
public class ItemStateListenerDemo extends MIDlet  implements CommandListener ,ItemStateListener{

    private Display display;
    private Form form;
    private Command exit;
    //声明2个TextFiled对象
    private TextField text1,text2;


    public ItemStateListenerDemo()
    {
        display=Display.getDisplay(this);
        exit=new Command("退出",Command.EXIT,1);       
        //根据不同的约束条件,实例化这2个textField对象
        text1=new TextField("输入","",30,TextField.ANY);
        text2=new TextField("输入的是:","",30,TextField.ANY);
        form=new Form("ItemStateListener接口测试");

        form.addCommand(exit);
        //将TextField添加到Form表单中
        form.append(text1);
        form.append(text2);


        form.setCommandListener(this);
        //向表单添加ItemStateListener监听器,参数为this
        form.setItemStateListener(this);
    }

    public void startApp() {
        display.setCurrent(form);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {

    }

    public void commandAction(Command c, Displayable d) {
      
    }

    public void itemStateChanged(Item item) {
        if (item==text1)
        {
            text2.setString(text1.getString());
        }
    }
}