在 j2me 中的自定义 GUI 中遍历

发布于 2024-12-19 10:53:34 字数 1417 浏览 3 评论 0原文

这是我的遍历方法代码,

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

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

Here is my Traverse method code

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

I am very new to Custom Item.
If I had done any wrong, let me know.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫罗兰の梦幻 2024-12-26 10:53:34

在 switch 语句中调用 traverse 的方式对我来说看起来很棘手:

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

到目前为止您发布的代码相当零散,但据我所知,上面将导致对 的无限递归调用遍历,最终以堆栈溢出错误结束。

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

The way how you invoke traverse from within switch statement looks slippery to me:

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

The code you posted so far is quite fragmentary but as far as I can tell, above will lead to infinite recursive calls for traverse, eventually ending in stack overflow error.

In your particular case this might be harmless though because you unconditionally return false from your method. Per my understanding this means that device will never attempt to invoke traverse with Canvas UP and other potentially dangerous values. Feel free to check lcdui CustomItem#traverse API documentation for more details if you're interested.

  • Given your code I think it makes good sense for you to study introductory code examples in tutorials. There are plenty available online - search the web for something like "MIDP tutorial CustomItem". Here's the link to one for example: Adding Custom Items to MIDP 2.0 Forms
     
    Also, if you are using Wireless Toolkit / Java ME SDK, you could check their code examples. Per my recollection, there were nice working examples of CustomItem code there.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文