【문제 설명】
Textedit은 GameCanvas를 사용하여 그린 텍스트 편집기입니다. 이 논문은 구현 방법을 제공하기위한 예제를 결합합니다.
【원칙】
1 그래픽과 GameCanvas를 사용하여 텍스트 상자와 커서를 그립니다.
2 입력 이벤트가 감지되면 고급 인터페이스 -> 텍스트 상자로 이동하십시오. 시스템 호출 입력 메소드를 통해 전체 입력.
3 TextBox에서 입력 한 값을 TextedIt 객체로 반환합니다.
【디자인 패턴】
이 과정은 실제로 장식 모드와 약간 유사합니다. 실제로 입력은 텍스트 상자로 장식되어 있습니다.
Code 코드 목록】
텍스트 공개 int int height; ) { / system.out.printlne "); 폭 , 너비+마진, Height+margin. y+1, width -1); +ft.stringwidth (텍스트)+Padding, 1, ft.getheight (), cursorblinkon); , int x, int y, int width, int 높이, 부울 cursorblinkon) {if (cursorblinkon) {ft = font.getfont .SetColor (0x0,0x0, 0x0); x+너비, x+높이)} popuptextbox.javapackage com.token.view; javax.microed CANVASTEXT는 개인 명령 velice args_t [] Maxsize, int 제약 조건. "Compart.Cancel, 1); String) args [0]! = null) args [0] : ""; System.out.println (Object_name); getString (); //system.out (canvastext); | args_t [3]! = null || : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : args_t[4]!=""||args_t[4 ]! Controller.HandleEvent (uicontroller.eventId.event_user_regist_edit_back, args); [4]! = "|| args_t [4]! Args [4] = areveraller.handleevent (uicontroller.event_user_regist_edit_back,} els e ife. || args_t [2]! = null || args_t [3] ""|| args_t [3] {argss [0] = arg_name [1] = Args; [2]; args_t [3]; CommandListener {public void commandAction (명령, 표시 가능한 disp) {if (command == okcommand) {closet extbox (true)} {closextbox (false)}} userregist.javapackage com .Token.vax.microedition.lcdui.graphics; . 개인 문자열 텍스트 텍스트 텍스트 텍스트 텍스트 _ Private int _ red _ red _ x intford _ x y; 개인 int 현재 선택한 index = 0; 개인 이름; userregist (uicontroller 컨트롤) {controller = "사용자 등록"; 메뉴 = 새로운 백 그라우드 = 새로운 userdatarecord (thistedit_naint); New TextedIt (this)} public void show (객체 [] args) {// todo auto-reconded setfullscreenmode (true); [0] : "(String) Args [1]! (String) Args [1]; ) Args [2] : ";"; (문자열) [4]; ")) {cursorblinkon1 = false; cursorblinkon2 = true; cursorblinkon3 = false; onsectrepedIndex = 1;} else if (editor.equals ("regist_passwd_re ")) {cursorblinkon1 = false; cursorblinkon2 = false; cursorblinkon3 = true; } //system.println). 그래픽); head drawhead (this, this.title); 0 : cursorblinkon2. cursorblinkon2 = retains} retains}; Y, CU rsorBlinkOn2 ); textEdit_passwd.drawTextBox(this, graphics, passwd_re, textEdit_passwd_re_x, textEdit_passwd_re_y, cursorBlinkOn3); textEdit_name.fl ushGraphics(); } public void drawBody() { int margin =5; ft = Font.getFont(Font.FACE_PROPORTIONAL,Font .Style_Bold, font.size_large) "username : /n"; for (int i = 0; i <info_wrap1.length; i ++) {Graphics.DrawString (info_wrap1 [i], 5, } textedit_name_y = 5; = StringDealMethod.format (info, width-10, ft); (info_wrap2 [i], 5, (i+info_wrap1.length) * ft.getheight ()+textedit_name.height+margin.top | graphics.left); +info_wrap2. ] = StringDealMethod.format (info, width-10, ft); drawString (info_wrap3 [i], 5, (i+info_wrap1.length+info_wrap2.length) * ft.getheight ()+textedit_name.height+textedit_passwd.height+2 * margin+40, gra phics.top | graphics.left). } textedit_passwd_re_x = 5; , passwd_re, textedit_passwd_re_x, cursorblinkon3) {graphics.setcolor (0xff, 0xff, 0xff); = System.CurrentTimeMillis (); //system.out.println (”); ")) {cursorblinkon1 =! cursorblinkon1; cursorblinkon2 = false; cursorblinkon3 = false;} else if (editor.equals ("regist_passwd ")) {false; cursorblin kon2 =! cursorblinkon3 = false; .Equals (regist_passwd_re ") {cursorblinkon2; (true) {checktimestamp (); ; ! = "&& passwd! =" "&& passwd_re! =" ") {if (passwd.equals (passwd_re)) {userrecord.db_deleteallrecord (); userdataitem (username +"," +passwd). AC TIVESCREEN ", NULL, UPDATE}; 컨트롤러 .HANDLEEVENT (UICONTROLLER.EVENTID.EVENT_NEXT_ACTIVE_TOKEN_TOKEN_SCREEN, ARGS);}} BREAK;} CASE KEYID.KEY_EDIT : CASE KEY_NUM1 : C ASE KEY_NUM2 : CASE KEY_NUM3 : CASE KEY_NUM3 : CASE key_NUM3 : CASE KEY_NUM3 : CASE KEY_NUM3 : CASE key_Num3 : CASE KEY_NUM3 : CASE key_NUM4 : CASE KEY_NUM3 : CASE KEY_NUM3 : : case key_num6 : case key_num8 : case key_num9 : {//system.out.println (redits = {object_name, username, passwd, passwd_re}; .event_user_regist_edit, arg}; {redraw ();
【분석】
1 텍스트 상자 그림 (textedit.java)
전략을 사용 하고이 매개 변수를 전달하는 도면을 구현하려면 GameCanvas 및 Graphics Object를 통과해야합니다. 또한 침대 아래 텍스트 상자의 왼쪽 상단 좌표 (x, y)와 커서 깜박임을 제어하는 변수 커서 블링콘.
공개 DrawTextBox (GameCanvas 캔버스, 문자열 텍스트, int X, Boolean Cursorblinkon) {//system.out.println (”); getfont (font.face_proporal, font.size_medium) width = 3*canvas.getWidth ()/5+2*padding; 패딩; 그래픽. 너비, 높이); setcolor (color.background) , x+패딩, y+padding, top.top.left); .flushgraphics (x, y, 너비, 높이);
2 커서를 그리십시오 (textedit.java)
공개 void DrawCursor (그래픽 그래픽, int X, int y, int width, int 높이, 부울 Cursorblinkon) {if (cursorblinkon) {ft = font.getfont (font.fac e_proporal, font.style_plain, font.size_medium); setfont (ft);
3 커서 플래싱 구현
커서 플래싱을 구현하려면 uicontroller.java 클래스에서 텍스트 상자의 뷰 클래스를 그려야하며 스레드 인터페이스를 구현해야합니다.
UICONTROLLER.JAVACASE eventId.event_user_regist_screen : reg.show (Args); () {system.currenttimeMillis (); . else (editor.equals.equals. run "); while (true) {checktimestamp (); redraw (); try {synchronized (this) {//system.out.println (”); Wait (50L);}} catch (예외 e) { e. printstacktrace ();
4 고급 인터페이스 텍스트 상자 서브 클래스 팝업 텍스트 박스를 호출하십시오
호출 할 때 호출 객체 이름, 개체 이름 편집 및 편집 상자 매개 변수가 PopUpTextBox 객체로 전달됩니다 (해야 할 경우 목적은 편집 상자의 값을 저장하는 것입니다. 그렇지 않으면 여러 통화가 반환되면 값이 값을 늘리는 것입니다. 다른 편집 상자는 비어 있습니다.
userregist.java (keypressed) case keyid.key_edit : case key_num0 : case key_num1 : case key_num2 : case key_num4 : case key_ num5 : case key_num7 : case key_num8 : case key_num8 : case key_num9 : {//system.out.out.out.out.out.outln. (편집자); argss = {object_name, username, passwd, passwd_re}; args) 중간에;
5 팝업 텍스트 박스 매개 변수 리셉션
public void init (object [] args) {object_name = ((String) args [0]! = null)? (String) args [0] : ""; ? (문자열) : "";
6 popuptextbox 입력 메소드에서 값 입력을 반환합니다.
if (업데이트) canvastext = this.getString ();
7 popuptextbox 입력 값 처리
호출 된 객체 및 편집 객체에 따라 입력 값을 처리하고 상위 오브젝트 편집 상자에 전달하십시오.
if (object_name.equals ( "registscreen")) {if (editor.equals ( "regist_name")) {if (args_t [3]! = ""|| args_t [3]! = null || args_t [4]! = "|| args_t! = args [1] = args; ] = args_t [4]; 컨트롤러 ]! = args_t [4] ""|| args_t [4] {args [0] = args [2] = args_t; [3] this.canvastext; 2]! = ""|| args_t [2]! = null || args_t [3]! = ""|| args_t [3]! = null) {args [0] = 객체 _name; args args [3];
8 입력 값 표시
(1) 새 개체를 만듭니다
Private TextedIt TextedIt_name;
(2) 입력 매개 변수를 허용합니다
Object_name = ((String) args [0]! = null)? (String) args [0] : ""; "; username = ((string) args [2]! = null)? (String) args [2] :"; passwd = ((String) args [3]! = null)? (String) args [3] : ""; Pass Passd_re = ((String) args [4]! = null)? (String) args [4] : "";
(3) 커서 제어, 편집 객체에 위치하고 편집 객체의 커서 깜박임 제어 (실행 메소드)
개인 void redraw (switch) {case 0 : {cursorberblinkon3 = "regist_name"; Break} COURSORBLINKON1 = false = "regist_passwd_re";
(4) 편집 상자의 그리기
private void redraw () {... textedit_name.drawtextbox (이, 그래픽, 사용자 이름, textedit_name_x, cursorblinkon1); (이것은 그래픽, passwd_re, textedit_passwd_re_x, textedit_passwd_re_y, cursorblinkon3);
달성 된 효과는 그림 1에 나와 있습니다.