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

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

001: //package com.s_cradle.improve.client;
002: 
003: import javax.microedition.lcdui.*;
004: //import com.s_cradle.improve.Constants;
005: 
006: 
007: /**
008:  * 会話画面を描画する Canvas です。
009:  *
010:  * @author Masaru Yoshimura
011:  */
012: public class M/*MessagingCanvas*/ extends H/*
                                      ImproveAbstractCanvas*/ implements CommandListener{
013:     //downsize 定数展開
014:     /*
015:     private static final int BUDDY_LOCATION_Y = TICKER_HEIGHT+6;
016:     private static final int MESSAGEBOX_LEFT_INTERVAL  = 5;
017:     private static final int MESSAGEBOX_RIGHT_INTERVAL = 5;
018:     private static final int MESSAGEBOX_UP_INTERVAL    = 50;
019:     private static final int MESSAGEBOX_DOWN_INTERVAL  = 5;
020:     private static final int MESSAGE_MAX = 30;
021:     private static final String MESSAGE_ATTACK = "攻撃しました。";
022:     */
023: 
024:     private static Command 退室/*exitCommand*/   =
                                                    new Command("退室", Command.BACK, 1);
025:     private static Command 攻撃/*attackCommand*/ =
                                                    new Command("攻撃", Command.ITEM, 2);
026:     private static Command 送信/*sendCommand*/   =
                                                      new Command("送信", Command.OK, 1);
027:     private static Command キャンセル/*cancelCommand*/ =
                                                 new Command("キャンセル", Command.CANCEL, 2);
028:     private TextBox A/*textBox*/;
029:     private A/*Buddy*/ Code/*buddy*/;
030:     private L/*MessageBox*/ StackMap/*messageBox*/;
031: 
032:     /**
033:      * コンストラクタ
034:      */
035:     public M/*MessagingCanvas*/(A/*Buddy*/ buddy_) {
036:         Code/*buddy*/ = buddy_;
037:         StackMap/*messageBox*/ = Code/*buddy*/.L/*messageBox*/;
038:         if(StackMap/*messageBox*/ == null){
039:             StackMap/*messageBox*/ = new L/*MessageBox*/(
                              5/*MESSAGEBOX_LEFT_INTERVAL*/,50/*MESSAGEBOX_UP_INTERVAL*/,
040:                                         getWidth()-5/*MESSAGEBOX_RIGHT_INTERVAL*/,
041:                                         getHeight()-5/*MESSAGEBOX_DOWN_INTERVAL*/);
042:            Code/*buddy*/.L/*messageBox*/ = StackMap/*messageBox*/;
043:         }
044:         addCommand(退室/*exitCommand*/);
045:         addCommand(攻撃/*attackCommand*/);
046:         setCommandListener(this);
047:     }
048: 
049:     /**
050:      * commandListener実装
051:      */
052:     public void commandAction(Command c, Displayable d){
053:         if( c.equals(退室/*exitCommand*/) ){
054:             Code/*buddy*/.L/*messageBox*/ = null;
055:             I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                              I/*ImproveMIDlet*/.StackMap/*listCanvas*/);
056:         } else if( c.equals(攻撃/*attackCommand*/) ){
057:             //downsize 即値の利用
058:             Z/*Task*/.Z/*getTask*/(5/*Task.TASK_SEND*/,new String[]{
059:                                      Code/*buddy*/.StackMap/*etc*/[0]/*account*/,
060:                                  String.valueOf(2/*Constants.MESSAGE_TYPE_ATTACK*/),
061:                                      "攻撃しました。"/*MESSAGE_ATTACK*/
062:             }).StackMap/*schedule*/(0);
063:         } else if( c.equals(送信/*sendCommand*/) ){ //送信TextBox
064:             //downsize 即値の利用
065:             Z/*Task*/.Z/*getTask*/(5/*Task.TASK_SEND*/,new String[]{
066:                                      Code/*buddy*/.StackMap/*etc*/[0]/*account*/,
067:                                 String.valueOf(1/*Constants.MESSAGE_TYPE_NORMAL*/),
068:                                      A/*textBox*/.getString()
069:             }).StackMap/*schedule*/(0);
070:             A/*textBox*/ = null;
071:             I/*ImproveMIDlet*/.Code/*setCurrent*/(this);
072:         } else if( c.equals(キャンセル/*cancelCommand*/) ){ //キャンセル
073:             A/*textBox*/ = null;
074:             I/*ImproveMIDlet*/.Code/*setCurrent*/(this);
075:         }
076:     }
077: 
078:     /**
079:     * 描画
080:      */
081:     public void paint(Graphics g){
082:         Z/*Task*//*Menu*/.StackMap/*draw3DRect*/(
               g, 0, 18/*TICKER_HEIGHT*/+1, getWidth(), getHeight()-18/*TICKER_HEIGHT*/-1,
083:                    (153<<16) | (153<<8) | 255/*
                                                 LIST_BG_COLOR*/, 0x00EEEEFF, 0x00000080);
084: 
085:         I/*ticker*/.Code/*paint*/(g);
086:         Code/*buddy*/.StackMap/*draw*/(g,getWidth(),18/*
                                        TICKER_HEIGHT*/+6/*BUDDY_LOCATION_Y*/,false,true);
087:         StackMap/*messageBox*/.I/*draw*/(g);
088:     }
089: 
090:     /**
091:      * キーハンドラ
092:      */
093:     protected void keyReleased(int keyCode){
094:         try{
095:             switch( getGameAction(keyCode) ){
096:                 case FIRE:
097:                     A/*textBox*/ = new TextBox(
                                    "メッセージ送信","",30/*MESSAGE_MAX*/,TextField.ANY);
098:                     A/*textBox*/.addCommand(送信/*sendCommand*/);
099:                     A/*textBox*/.addCommand(キャンセル/*cancelCommand*/);
100:                     A/*textBox*/.setCommandListener(this);
101:                     I/*ImproveMIDlet*/.Code/*setCurrent*/(A/*textBox*/);
102:                     break;
103:                 case LEFT:
104:                     I/*ImproveMIDlet*/.Code/*setCurrent*/(
                                              I/*ImproveMIDlet*/.StackMap/*listCanvas*/);
105:                     break;
106:                 default:
107:                     StackMap/*messageBox*/.A/*processKeyRelease*/(
                                                        getGameAction(keyCode),keyCode);
108:             }
109: 
110:             repaint();
111:         } catch(IllegalArgumentException ex){
112:             //NOP
113:         }
114:     }
115: }