ホーム > デベロッパ > J2ME / MIDP プログラミング > 実機に載せよう

第4回:実機に載せよう(ダウンサイズ)

001: //package com.s_cradle.improve.client;
002: 
003: import javax.microedition.lcdui.TextBox;
004: import javax.microedition.lcdui.TextField;
005: import javax.microedition.lcdui.CommandListener;
006: import javax.microedition.lcdui.Command;
007: import javax.microedition.lcdui.Displayable;
008: import javax.microedition.lcdui.Form;
009: import javax.microedition.lcdui.Item;
010: import javax.microedition.lcdui.StringItem;
011: //import com.s_cradle.improve.Constants;
012: 
013: /**
014:  * Copyright (C) 2003 Sophia Cradle, Inc.
015:  *
016:  * 本人フォーカス時の Menu です。
017:  *
018:  * @author Masaru Yoshimura
019:  */
020: public class J/*MainMenu*/ extends Z/*Task*//*Menu*/ implements CommandListener{
021:    private static final String[] プロフィール/*ITEMS*/ = {"ステータスを変える",
022:         "ステータスを書き込む","友達を加える","プロフィール",
                                                  "脱会する","IMを終わる","キャンセル"};
023:     //downsize 定数展開
024:     /*
025:     private static final String PRE_TITLE = "メニュー:";
026: 
027:     private static final int ITEM_CHENGE_STATUS = 0;
028:     private static final int ITEM_WRITE_IN_STATUS = 1;
029:     private static final int ITEM_ADD_FRIEND = 2;
030:     private static final int ITEM_PROFILE = 3;
031:     private static final int ITEM_WITHDRAW = 4; //脱会
032:     private static final int ITEM_END_IM = 5;
033:     private static final int ITEM_CANCEL = 6;
034:     */
035: 
036:     private TextField[] キャンセル/*textFields*/ = new TextField[2];
037:     //downsize 配列化
038:     //private TextField nicknameTextField;
039:     //private TextField phoneNumberTextField;
040:     private A/*Buddy*/ 脱会する/*buddy*/;
041: 
042:     /**
043:      * コンストラクタ
044:      */
045:     public J/*MainMenu*/(A/*Buddy*/ buddy_) {
046:         Z/*initializeMenu*//*super*/(
            "メニュー:"/*PRE_TITLE*/+buddy_.StackMap/*etc*/[1]/*nickname*/,プロフィール/*ITEMS*/);
047:         脱会する/*buddy*/ = buddy_;
048:     }
049: 
050:     /**
051:      * キーハンドラ
052:      */
053:     protected Z/*Task*//*Menu*/ StackMap/*processFireKeyRelease*/(){
054:         //System.out.println("cursor:"+cursor);
055:         TextBox textBox;
056: 
057:         switch(Z/*idata*/[0]/*cursor*/){
058:             case 0/*ITEM_CHENGE_STATUS*/:
059:                 D/*CreateTask*//*ChangeStatusMenu*/ create = new D/*CreateTask*/();
060:                 create.D/*initializeChangeStatusMenu*/();
061:                 return create;
062:             case 1/*ITEM_WRITE_IN_STATUS*/:
063:                 textBox = new TextBox(
                               脱会する/*buddy*/.StackMap/*etc*/[1]/*nickname*/+":ステータス",
064:                         脱会する/*buddy*/.StackMap/*etc*/[2]/*description*/,20/*
                                              Constants.DESCRIPTION_MAX*/,TextField.ANY);
065:                 textBox.setCommandListener(this);
066:                 textBox.addCommand(StackMap/*okCommand*/);
067:                 textBox.addCommand(Code/*cancelCommand*/);
068:                 I/*ImproveMIDlet*/.Code/*setCurrent*/(textBox);
069:                 return null;
070:             case 2/*ITEM_ADD_FRIEND*/:
071:                 textBox = new TextBox(
                           "友達追加","",10/*Constants.ACCOUNT_MAX*/,TextField.EMAILADDR);
072:                 textBox.setCommandListener(this);
073:                 textBox.addCommand(StackMap/*okCommand*/);
074:                 textBox.addCommand(Code/*cancelCommand*/);
075:                 I/*ImproveMIDlet*/.Code/*setCurrent*/(textBox);
076:                 return null;
077:             case 3/*ITEM_PROFILE*/:
078:                 //downsize 即値の利用
079:                 Form form = new Form("プロフィール",new Item[]{
080:                     new StringItem(
                              "アカウント: ",脱会する/*buddy*/.StackMap/*etc*/[0]/*account*/),
081:                   キャンセル/*textFields*/[0]/*nicknameTextField*/ = new TextField(
     "ニックネーム: ",脱会する/*buddy*/.StackMap/*etc*/[1]/*
                                   nickname*/,9/*Constants.NICKNAME_MAX*/,TextField.ANY),
082:                     キャンセル/*textFields*/[1]/*phoneNumberTextField*/ = 
           new TextField("電話番号: ",脱会する/*buddy*/.StackMap/*etc*/[3]/*phoneNumber*/,
                                    11/*Constants.PHONENUMBER_MAX*/,TextField.PHONENUMBER)
083:                 });
084:                 form.addCommand(StackMap/*okCommand*/);
085:                 form.addCommand(Code/*cancelCommand*/);
086:                 form.setCommandListener(this);
087:                 I/*ImproveMIDlet*/.Code/*setCurrent*/(form);
088:                 return null;
089:             case 4/*ITEM_WITHDRAW*/:
090:                 E/*DeleteTask*//*TwoChoiceMenu*/ menu = new E/*DeleteTask*/();
091:                 menu.E/*initializeTwoChoiceMenu*/(
                                       "退会しますか?",0/*TwoChoiceMenu.MENU_WITHDRAW*/);
092:                 return menu;
093:             case 5/*ITEM_END_IM*/:
094:                 E/*DeleteTask*//*TwoChoiceMenu*/ menu2 = new E/*DeleteTask*/();
095:                 menu2.E/*initializeTwoChoiceMenu*/(
                                           "終了しますか?",1/*TwoChoiceMenu.MENU_QUIT*/);
096:                 return menu2;
097:             case 6/*ITEM_CANCEL*/:
098:             default:
099:                 break;
100:         }
101: 
102:         return null;
103:     }
104: 
105:     /**
106:      * CommandListener実装
107:      */
108:     public void commandAction(Command c, Displayable d){
109:         //downsize 即値の利用
110:         //Task task, task2;
111:         if( c.equals(Code/*cancelCommand*/) ){
112:             I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                              I/*ImproveMIDlet*/.StackMap/*listCanvas*/);
113:         } else if( c.equals(StackMap/*okCommand*/) ){
114:             switch(Z/*idata*/[0]/*cursor*/){
115:                 case 1/*ITEM_WRITE_IN_STATUS*/:
116:                     Z/*getTask*/(4/*Task.TASK_SET*/,new String[]{
117:                                String.valueOf(5/*Constants.ITEM_INDEX_DESCRIPTION*/),
118:                                 ((TextBox)d).getString()}).StackMap/*schedule*/(0);
119:                     I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                               I/*ImproveMIDlet*/.StackMap/*listCanvas*/);
120:                     break;
121:                 case 2/*ITEM_ADD_FRIEND*/:
122:                     Z/*getTask*/(2/*Task.TASK_ADD*/,new String[]{
                                       ((TextBox)d).getString()}).StackMap/*schedule*/(0);
123:                     break;
124:                 case 3/*ITEM_PROFILE*/:
125:                     Z/*getTask*/(4/*Task.TASK_SET*/,new String[]{
126:                                 String.valueOf(2/*Constants.ITEM_INDEX_NICKNAME*/),
127:                                 キャンセル/*textFields*/[0]/*
                                nicknameTextField*/.getString()}).StackMap/*schedule*/(0);
128:                     Z/*getTask*/(4/*Task.TASK_SET*/,new String[]{
129:                                 String.valueOf(3/*Constants.ITEM_INDEX_PHONE*/),
130:                                 キャンセル/*textFields*/[1]/*
                             phoneNumberTextField*/.getString()}).StackMap/*schedule*/(0);
131:                     break;
132:             }
133:             I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                              I/*ImproveMIDlet*/.StackMap/*listCanvas*/);
134:         }
135:     }