2011-12-03 28 views
0

這裏是我的特拉弗斯方法的代碼導線自定義GUI在J2ME

protected boolean traverse(int dir, int viewportWidth, int viewportHeight, 
     int[] visRect_inout) { 
    try { 
     if (hori && vert) { 
      // CustomItems items=new CustomItems("Hi"); 
      switch (dir) { 
       case Canvas.DOWN: 
        this.a=dir;     //Canvas.DOWN 
        this.b=viewportWidth;  //b=2 
        this.c=viewportHeight;  //c=3 
        this.d=visRect_inout;  //d={2,2,250,250} 
        this.traverse(Canvas.UP, b, c, d); 

        break; 
       case Canvas.UP: 
        this.a=dir; 
        this.j=viewportWidth; 
        this.k=viewportHeight; 
        this.d=visRect_inout; 
        this.traverse(Canvas.UP, j, k, d); 
        break; 
       case Canvas.LEFT: 
        this.a=dir; 
        this.j=viewportWidth; 
        this.k=viewportHeight; 
        this.d=visRect_inout; 
        this.traverse(Canvas.LEFT, j, k, d); 
        break; 
       case Canvas.RIGHT: 

        break; 
      } 
     } 

    } catch (Exception e) { 
     System.out.println("Exception " + e); 
    } 
    return false; 
} 

我是很新的自定義項。
如果我做錯了,請告訴我。

+0

什麼是_CustomGUI_?什麼是_Listitem_? [MIDP 2 lcdui API]中沒有這樣的對象(http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/package-summary.html )。你的意思是'CustomItem'和'ChoiceGroup'? – gnat

+0

@ user1078616,你的問題非常模糊和不確定。用更具體的上下文支持你的問題,屏幕截圖,提及參考庫和使用的開發環境。 – Vimal

回答

0

你如何從switch語句中調用traverse的方式看起來滑對我說:

    this.traverse(Canvas.UP, b, c, d); // ... 
        // ...and similar in cases Canvas.UP, LEFT 

您發佈至今的代碼是很零碎的,但據我所知,上面會導致無窮的遞歸調用爲traverse,最終以堆棧溢出錯誤結束。

在您的具體情況下,這可能是無害的,但因爲您無條件地從您的方法返回false。根據我的理解,這意味着設備將永遠不會嘗試使用Canvas UP和其他潛在危險值進行遍歷。如果您有興趣,請隨時查詢lcdui CustomItem#traverse API documentation瞭解更多詳情。

  • 鑑於您的代碼,我認爲您應該在教程中學習介紹性的代碼示例。網上有很多可用的東西 - 在網絡上搜索諸如「MIDP tutorial CustomItem」之類的東西。下面是一個例子的鏈接:Adding Custom Items to MIDP 2.0 Forms
     
    此外,如果您使用的是Wireless Toolkit/Java ME SDK,您可以查看他們的代碼示例。根據我的回憶,在那裏有很好的CustomItem代碼工作示例。
+0

謝謝巴迪..我正在努力....... – Ravi