【问题标题】:Traverse in custom GUI in j2me在 j2me 中的自定义 GUI 中遍历
【发布时间】:2011-12-03 04:52:09
【问题描述】:

这是我的 Traverse 方法代码

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;
}

我对自定义项目非常陌生。
如果我做错了什么,请告诉我。

【问题讨论】:

  • 什么是 CustomGUI列表项是什么? MIDP 2 lcdui API 中没有此类对象。你的意思是CustomItemChoiceGroup
  • @user1078616,您的问题非常模糊且不确定。使用更具体的上下文、屏幕截图、提及使用的参考库和开发环境来支持您的问题。

标签: java-me custom-controls midp lcdui


【解决方案1】:

从 switch 语句中调用 traverse 的方式对我来说看起来很滑:

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

到目前为止,您发布的代码非常零碎,但据我所知,上述代码将导致对traverse 的无限递归调用,最终以堆栈溢出错误告终。

在您的特定情况下,这可能是无害的,因为您无条件地从您的方法中返回 false。根据我的理解,这意味着设备永远不会尝试使用 Canvas UP 和其他潜在危险值调用 traverse。如果您有兴趣,请随时查看lcdui CustomItem#traverse API documentation 了解更多详情。

  • 鉴于您的代码,我认为您学习教程中的介绍性代码示例非常有意义。网上有很多可用的 - 在网上搜索“MIDP 教程 CustomItem”之类的内容。例如,这是一个链接:Adding Custom Items to MIDP 2.0 Forms

    此外,如果您使用的是 Wireless Toolkit / Java ME SDK,您可以查看他们的代码示例。据我回忆,那里有很好的 CustomItem 代码示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-03
    • 2021-05-31
    • 2011-09-24
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 2015-06-10
    • 2019-06-05
    相关资源
    最近更新 更多