【وصف المشكلة】
TextedIt هو محرر نصوص مرسومة باستخدام Gamecanvas. تجمع هذه الورقة بين أمثلة لتوفير طرق التنفيذ.
【مبدأ】
1 استخدم الرسومات و gamecanvas لرسم مربعات نصية ومؤشرات.
2 عند اكتشاف حدث إدخال ، انقلب إلى الواجهة المتقدمة -> مربع النص. أكمل الإدخال من خلال طريقة إدخال استدعاء النظام.
3 إرجاع القيمة التي تم إدخالها بواسطة TextBox إلى كائن TextedIt.
【نمط التصميم】
هذه العملية تشبه إلى حد ما الوضع الزخرفي.
【قائمة الكود】
textedit.javapackage com.token.view. ؛ ) {/system.out.println ( ) ؛ ، الهامش ، الهامش) ؛ Y+1 ، العرض -1 ، 1) ؛ +ft.StringWidth (Text)+Padding ، y+padding ، 1 ، ft.getheight () ، cursorblinkon) ؛ ، int x ، int y ، int ، int legh ، boolean cursorblinkon) {if (cursorblinkon) .setColor (0x0،0x0 ، 0x0) import canvastext = " MaxSize ، int intraints) "إلغاء" ، command.cancel ، 1) ؛ سلسلة) args [0]! = null) (سلسلة) args [0]: "" ؛ System.out.println (Object_name) ؛ getString () ؛ | args_t [3]! = null ||. ::::::::::::::::::::::::: :::::::::::::::::::::: :::::::::::::::::::::::::: :::::::::::::::: args_t [4]! = "" || args_t [4 ]! controller.handleevent (uicontroller.eventid.event_user_regist_edit_back ، args) ؛ [4]! = "|| args_t [4]! = NULL) ؛ || args_t [2]! = null || args_t [3]! = "|| args_t [3]! = null) {args [0] = object_name ؛ [2] ؛ CommandListener {public void command (command command ، displable) {if (command == okCommand) {closet extbox (true) ؛ .token.view; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; import ja vax.microedition.lcdui.game.GameCanvas; import com.token.model. *; import com.token.util . العنوان الخاص بالسلسلة الخاصة ؛ Y ؛ اسم المستخدم الخاص ؛ userregist (uicontroller control) {super (false) ؛ قائمة جديدة (هذا) ؛ New TextedIt (هذا) ؛ [0]: "" ؛ ) args [2]: "" ؛ (سلسلة) args [4]: "؛ ")) {cursorblinkon1 = false ؛ cursorblinkon2 = true ؛ cursorblinkon3 = false ؛ حاليًا selectedIndex = 1 ؛} آخر if (editor.equals (" regist_passw_re ")) {cursorblinkon1 = false ؛ cursorblinkon2 = false ؛ } //syster.println(oBject_name) ؛ الرسومات) ؛ 0: cursorblinkon 2 ؛ Cursorblinkon 2 = regist_pass WD_Y ، CU RSORBLINKON2) ؛ أونت .style_bold ، font.size_large) ؛ ) ؛ } textedit_name_x = 5 ؛ = stringdealmethod.format (info_wrap2 [i] ، 5 ، (i+info_wrap1.length) * ft.getheight () textedit_name +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 | ؛ ، passwd_re ، textedit_passw_re_x ، textedit_passw_y ، cursorblinkon3) ؛ = System.CurrentTimEmillis () ؛ ")) {cursorblinkon1 =! cursorblinkon1 ؛ cursorblinkon2 = false ؛ cursorblinkon3 = false ؛} آخر if (editor.equals (" regist_passwd ")) {cursorblinkon1 = false ؛ cursorblin kon2 =! cursorblinkon2 ؛ .equals (regist_passwd_re ") (صحيح) {checkestamp () ؛ ! = "" && passwd! = "" && passwd_re! = "") {if (passwd.equals (passwd_re)) {userrecord.db_deleteallrecord () ؛ userDataitem (1 ، (اسم المستخدم +"، +passwd). ac tivescreen "، null ، update} ؛ controller .handleevent (uicontroller.eventid.event_next_teact_token_screen ، args) ؛}} : case key_num6: case key_num7: case key_num8: case key_num9: {//system.out.println chongeritor) ؛ event_user_regist ، args) ؛ {RedRaw ()
【تحليل】
1 رسم مربعات النص (textedit.java)
تحتاج إلى تمرير Gamecanvas وكائنات الرسومات لتنفيذ الرسم ، ومن يستخدم الاستراتيجية ومن يمرر هذه المعلمة. بالإضافة إلى ذلك ، فإن إحداثي الزاوية اليسرى العلوية (x ، y) من مربع النص أسفل السرير والمتغير المؤشر الذي يتحكم في وميض المؤشر.
Public Void DrawTexbox (Gamecanvas Canvas ، رسومات الرسومات ، int x ، int y ، boolean cursorblinkon) {//system.out.println("draw " . Padding ؛ العرض ، الرسومات ، x+padding ، y+padding ، graphics.top | graphics.left) ؛ .
2 ارسم المؤشر (textedit.java)
public void drawcursor (رسومات الرسومات ، int x ، int y ، int ، int ، int cursorblinkon) {if (cursorblinkon) {ft = font.getfont (font.fac e_proportional ، font.style_plain ، font.size_medium) ؛ setfont (ft) ؛
3 تنفيذ وميض المؤشر
يتطلب تنفيذ وميض المؤشر الخيط.
UICONTROLLER.JAVACASE EVENTID.EVENT_NEXT_REGIST_SCREEN () {long currentime = CurrentTimeMillis () ؛ .equals (regist_name ") } if (editor.equals ("regist_passw_re") قم بتشغيل ") ؛ بينما (صواب) {checkestamp () ؛ redraw () ؛ حاول {synchronized (this) {//system.out.println("3") ؛ wait (50l) ؛}} catch (استثناء e) { هـ.
4 استدعاء مربع النصوص المتقدمة مربع الفئة الفرعية popupuptbox
عند الاتصال ، يتم تمرير اسم كائن الاتصال واسم تحرير الكائن ومعلمات مربع التحرير إلى كائن popupuptextbox (يجب أن يكون له ، والغرض من ذلك هو حفظ قيمة مربع التحرير. وإلا ، عند إرجاع مكالمات متعددة ، القيم من صناديق التحرير المختلفة سيتم تحديثها لتفريغ.
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: case key_num9: (محرر) ؛ args) ؛
5 استقبال معلمة Popupuptextbox
public void init (Object [] args) {Object_name = ((سلسلة) args [0]! = null)؟ (سلسلة) args [0]: "" ؛ ؟ (سلسلة) args [1]: "
6 Popupuptexbox إرجاع إدخال القيمة من طريقة الإدخال
إذا (التحديث) canvastext = this.getString () ؛
7 معالجة قيمة الإدخال Popupuptextbox
معالجة قيمة الإدخال وفقًا للكائن المسمى والكائن التحرير ، وقم بتمريره إلى مربع تحرير الكائن الأصل.
if (object_name.equals ("RegiScreen"))) {if (editor.equals ("RegiSt_Name")) {if (args_t [3]! = "" || args_t [3]! = null || args_t [4]! = "|| args_t [4] = null) {args [0] = Object_name ؛ ] = args_t [4] ؛ ]! = null || args_t [4]! = " [3] = this.canvastext ؛ 2]! = "" || args_t [2]! = null || args_t [3]! = "" || args_t [3]! = null) {args [0] = Object_name ؛ args [2] = args_t [2]
8 عرض قيم الإدخال
(1) إنشاء كائن جديد
private textedit_name ؛
(2) قبول معلمات الإدخال
Object_name = ((سلسلة) args [0]! = null)؟ (سلسلة) args [0]: "" ؛ "؛ اسم المستخدم = ((سلسلة) args [2]! = null)؟ (سلسلة) args [2]:" "؛ passwd = ((سلسلة) args [3]! = null)؟ (سلسلة) args [3] : "" ؛
(3) التحكم في المؤشر ، وتحديد موقع كائن التحرير ، والتحكم في وميض المؤشر لكائن التحرير (تشغيل طريقة)
private void () {SwitchedIndex) CROP ؛
(4) رسم مربع تحرير
private void redraw () {... textedit_name.drawtextbox (هذا ، اسم المستخدم ، textedit_name_x ، textedit_name ، cursorblinkon1) ؛ مربع النص (هذا ، الرسومات ، passwd_re ، textedit_passw_re_x ، textedit_passw_re_y ، cursorblinkon3) ؛
يظهر التأثير الذي تم تحقيقه في الشكل 1: