---
title: "J2ME学习（2）-------界面及打包"
author: "GH0769"
date: "2010-05-06T12:33:12Z"
tags: []
categories: ["移动开发"]
slug: "j2me-2"
draft: false
lastmod: "2010-05-06T12:33:12Z"
id: 660247
url: "https://gh0769.iteye.com/blog/660247"
---

J2ME提供的工具CREATE PACKAGE进行打包。

在deployed目录下生成一个jad和一个jar文件，一般的手机需要jar文件即可。有时需要两个。

 

获得当前MIDLET的显示：

   display = Display.getDisplay(this);

显示可视化对象：

display.setCurrent(form);

 

添加命令

private Command del = new Command("删除", Command.SCREEN, 1);

private Command back = new Command("返回", Command.BACK, 1);

        form.addCommand(back);  
        form.addCommand(del);  
        form.addCommand(edt);

 

事件：

    private class CmdListener implements CommandListener  
    {  
        public void commandAction(Command c, Displayable d)  
        {  
             
        }  
    }

或： extends MIDlet implements CommandListener

 

form.setCommandListener(new CmdListener());

form.setCommandListener(this);

        if(c == del)  
            System.out.println("删除");  
        else if(c == edt)  
            System.out.println("编辑");  
        else if(c == back)  
            notifyDestroyed();

c.getLabel.equal()

 

 

List list = new List("sdfsdfsdf", List.MULTIPLE);

display.setCurrent(list);  
         
        list.append("a", null);  
        list.append("b", null);

Image image = Image.createImage("/shoujitu.gif");  
            list.append("b", image);

    if(c == List.SELECT\_COMMAND)//特指IMPLICIT类型的List command

 

list.setTicker(new Ticker("sdklfsdfkljsdklfjsldf"));

 

alert

 

 

Date date = new Date();  
        DateField dateField = new DateField("sdklfjsdklf", DateField.DATE);  
        dateField.setDate(date);  
        form.append(dateField);         
        ChoiceGroup group = new ChoiceGroup("性别", ChoiceGroup.POPUP);  
        group.append("男", null);         
        form.append(group);         
        Gauge gauge = new Gauge("进度条", true, 320, 0);  
        form.append(gauge);

 

 

ImageItem imageItem = new ImageItem("sdklfjsdklf", Image.createImage("/shoujitu.gif"), ImageItem.LAYOUT\_CENTER,  
            "lksdjklsdf");  
            form.append(imageItem);  
             
            TextField field = new TextField("TextField", "5", 8, TextField.NUMERIC);         
            form.append(field);

 

 

StringItem item = new StringItem("abc", "dddd", StringItem.BUTTON);  
            item.addCommand(new Command("sdkfljsdlf", Command.BACK, 0));  
            form.append(item);

 

ItemCommandListener

private Command command = new Command("删除", Command.ITEM, 2);

field.addCommand(command);     
        field1.addCommand(command);

field.setItemCommandListener(this);         
        field1.setItemCommandListener(this);

    public void commandAction(Command c, Item i)  
    {  
        TextField field12 = (TextField)i;  
        int pos = field12.getCaretPosition();  
        field12.delete(pos - 1, 1);  
    }