【問題の説明】
TextEditは、Gamecanvasを使用して描かれたテキストエディターです。このペーパーでは、例を組み合わせて実装方法を提供します。
【原理】
1グラフィックとゲームカンバを使用して、テキストボックスとカーソルを描画します。
2入力イベントが検出されたら、Advanced Interface-> TextBoxにジャンプします。システムコール入力メソッドを介して入力を完了します。
3テキストボックスで入力された値をTextEditオブジェクトに返します。
【デザインパターン】
このプロセスは、実際には装飾モードに少し似ています。
【コードリスト】
text.javapackage com.token.view.compontion.lcdui.font; ;パブリックイントアットハイト; ){ / system.println("draw "); ; width.getWidth()/5+2* 、幅+マージン+マージン); y+1、wid1、height -1); +ft.StringWidth(テキスト)+パディング、1、ft.getheight()、carsorblinkon) 、int x、int y、int width、int cursorblinkon){ft = font.getfont(font.face_propertal、font.style_plain、font.size_medium); .setcolor(0x0,0x0、0x0); javax.lcdui.display.lcdui.lcdui.lcdui.lcdui.textbox; canvastext = "" Maxsize、int Constraints) 「キャンセル」、Cancel、1); string)[0]!= null)?(string)args [0]:(string)arg [1]!= null)args [1]: ""; system.out.println(object_name); getString(); //system.out(canvastext); | args_t [3]!= null ||。 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::づ 火::::: ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::4] ]!= args [0] = args [2] = controller.handleevent(uicontroller.eventid.event_user_regist_edit_back、args); [4]!= "" || args_t!= null){0] = object_name; ; args [4] = args_t [4]; || args_t [2]!= null || args_t!= "" || args_t!= null){args [0] = object_name [2]; commandListener {public void commandaction(command command、displayable disp){command == okcommand){command == cancelcommand){closetextbox(false)}} .token.view.lcdui.font; 。 Private TextEdit_PaSSWD; WD_RE_Y; PrivateSelectedIndex = 0; PassWD_REのプライベートユーザーレジスト(super);メニュー(This); new Textedit(this); public void show(Object [] args) [0]: "";(string)args [1]?(string): ""; )args [2]: ""; passwd =((string)args [3]!= null)arg [3]: ""; (文字列): ""; ")){cursorblinkon1 = false; cursorblinkon2 = true; cursorblinkon3 = false;現在selectedindex = 1;} else if(editor.equals(" regist_passwd_re ")){cursorblinkon1 = false; false; cursorblinkon2 = cursorblinkon3 = fals fals; } //System.println(//system()draw();グラフィックス) 0:cursorblinkon3 = false; cursorblinkon2 = "regist_passwd_re"; _passwd_y、cu rsorblinkon2); 、フォント.style_bold、font.size_large); ; for(int i = 0; i <info_wrap1.length; i ++){graphics.drawstring(info_wrap1 [i]、5、(i) * ft.getheight()+40、graphics.top | graphics.left); } TextEdit_x = 5; = stringdealmethod.format(width-10、ft); (info_wrap2 [i]、5、(i+info_wrap1.length) * ft.getheight()+textedit_name.height+40、graphics.top | graphics.left); +info_wrap2。 ] = StringDealMethod.Format(width-10、ft); drawstring(info_wrap3 [i]、5、(i+info_wrap1.length+info_wrap2.length) * ft.getheight()+textedit_name.height+textedit_passwd.heigh ; textedit_passwd_re_x = 5; 、passwd_re、textedit_re_x、textedit_passwd_y、cursorblinkon3); = system.currenttimemillis(); "){cursorblinkon1 =!cursorblinkon1; cursorblinkon2 = false; cursorblinkon3 = false;} else if(editor.equals(" regist_passwd ")){cursorblinkon1 = false; false; cursorblinkon3 = cursorblinkon3 = false; 。 "regist_passwd_re") (true){checktimestamp(); ;}}} protec ted keypressed(int keycode){case keyid.soft_right:{controller.eventid.event.event_exit、null) != "" && passwd!= "" && passwd_re!= ""){if(passwd.equals(passwd_re)){userrecord.db_deleteallrecord() userdataitem(username +"、" +passbytes()); Ac Tivescreen "、null、update}; controller .handleevent(uicontroller.eventid.event_next_active_token_screen、args);}} case keyid.key_edit:case key_num0:case key_num1:c ase key_num2:case key_num5:case key_num5 :case key_num6:case key_num8:case key_num9:{//system.out.println(editor); .event_user_regist_edit、defauts} {redRaw();
【分析】
テキストボックスの図面(textedit.java)
GameCanvasとグラフィックスオブジェクトを渡して、戦略を使用し、このパラメーターを渡す描画を実装する必要があります。さらに、ベッドの下のテキストボックスの左上隅の座標(x、y)と、カーソルの点滅を制御する可変カーソルブリンコン。
public void drawtextbox(gamecanvasグラフィックス、int x、int y、boolean cursorblinkon){padding = 4; GetFont(font.Style_plain、font.setfont(ft);パディング。 width、graphics.setcolor(color.backics.fillrect(width-1、height-1); 、X+パディング、Y+パディング、グラフィックス。左); .flushgraphics(x、y、width、height);
2カーソルを描く(textedit.java)
public void drawcursor(グラフィックグラフィックス、int x、int y、int width、boolean cursorblinkon){ft = font.getfont(font.fac e_properal、font.style_plain、font.size_medium); setfont(ft);
3カーソルフラッシュを実装します
カーソルフラッシュの実装には、uicontroller.javaクラスでスレッドが必要です。
uicontroller.javaCase eventid.event_next_user_regist_edit_back:{reg.show(args); (){long culntime.currenttimemillis(); 。 "regist_name") } editor.equals( "regist_passwd_re"){cursorblinkon2 = false 3 = cursorblinkon3; run "); while(true){checktimestamp(); redraw(); try {synchronized(this){//system.out.println("3"); wait(50l);}} catch(exception e){ e。
4 Advanced Interface Textbox Subclass Popuptextboxを呼び出します
呼び出しの場合、コールオブジェクト名、オブジェクト名の編集、および編集ボックスパラメーターがpopuptextboxオブジェクトに渡されます(目的は編集ボックスの値を保存することです。さまざまな編集ボックスが空になります。
userregist.java(keypressed)case keyid.key_edit:case key_num0:case key_num1:case key_num2:case key_num3:case key_num4:case key_num5:case key_num6:case key_num7:case key_num8:ケースkey_num9 (編集者); args)
5 popuptextboxパラメーター受信
public void init(object [] args){object_name =((string)args [0]!= null)?(string)arg [0]: ""; ?(string): "";
6 popuptextbox入力メソッドから値入力を返します
if(update)canvastext = this.getString();
7 popuptextbox入力値処理
呼び出されたオブジェクトと編集オブジェクトに従って入力値を処理し、親オブジェクトの編集ボックスに渡します。
if(object_name.equals( "registscreen")){if(editor.equals( "regist_name")){if(args_t!= "|| args_t [3]!= null || args_t [4]! = "|| args_t!= null){0] = object_name ] = args_t [4]; controller.handleevent(uicontroller.event.event_user_regist_edit_back、args); ]!= null || args_t!= "|| args_t!= null){object_name [1] = args_t; [3] = canvastext; 2]!= "" || args_t [2]!= null || args_t [3] args [2] = args_t = args_t [4] = controler. handlevent(uicontroller.event_user_regist_edit_ba ck、}}}
8入力値の表示
(1)新しいオブジェクトを作成します
private textedit textedit_name;
(2)入力パラメーターを受け入れます
object_name =((string)args [0]!= null)?(string)args [0]:((string)arg [1]!= null)?(string)arg [1]: " "; username =((string)args [2]!= null)?(string)args [2]:" "; passwd =((string)arg [3]!= null)?(string)arg [3] : ""; passwd_re =((string)args [4]!= null)args [4]: "";
(3)カーソル制御、編集オブジェクトへの配置、編集オブジェクトのカーソルフラッシュの制御(実行方法)
Private redRaw(){Case 0:{cursorblinkon3 = false; BREAK;
(4)編集ボックスの図面
private void redraw(){... textedit_name.drawtextbox(This Graphics、Username、TextEdit_name_y、cursorblinkon1) D.DrawTextBox(これ、 Graphics、passwd_re、textedit_passwd_re_x、textedit_passwd_y、cursorblinkon3);
達成された効果を図1に示します。