黑莓 API / 菜单项

发布于 2024-11-15 20:47:56 字数 1481 浏览 1 评论 0原文

我刚刚学习黑莓 API,试图按照黑莓开发网站上的教程进行操作,但我有点困惑。在界面教程中,他们给出了以下制作菜单项的说明......

private MenuItem _changeCapitol = new MenuItem("Change Capitol", 110, 10) 
{ 
    public void run() 
    { 
        if (displayed == 0) 
            _canadaCapitol = _input.getText(); 
        else if (displayed == 1) 
            _ukCapitol = _input.getText(); 
        else if (displayed == 2) 
            _usCapitol = _input.getText(); 
    } 
}; 

这一切都很好,现在可以使用。问题是用于创建 MenuItem 的方法已被弃用。所有教程似乎都是针对 4.0 的。我想学习如何以正确的方式执行此操作,因此我查阅了 6.0 API 参考。我尝试将其转换为当前方法,但我无法完全正确。这是我最接近的...

private MenuItem _changecapitol = new MenuItem(new StringProvider("Change Capitol"), 110, 10);
changecapitol.setCommand(new Command(CapitolChange()));
class CapitolChange extends CommandHandler
{
    public void execute(ReadOnlyCommandMetadata metadata, Object context)
    {
        if (displayed == 0) 
            _canadaCapitol = _input.getText(); 
        else if (displayed == 1) 
            _ukCapitol = _input.getText(); 
        else if (displayed == 2) 
            _usCapitol = _input.getText();
    }

}

似乎构造函数的括号内确实应该有一些东西,但我无法想象那可能是什么。如果我正确理解了该参考,那么该功能就位于 CommandHandler 内部,所以我认为我的部分是正确的。现在的问题是 Eclipse 在 CapitolChange 构造函数之前抛出一个错误。

changecapitol.setCommand(new Command(CapitolChange()));

我实际上在这条线上遇到了多个错误。一个是错误的构造错误,另一个声称在“setCommand”之后我需要一个“=”。 API 中没有这样的内容,而且在语法上看起来似乎是错误的。我正在调用一个方法而不是赋值。正确的?不?难道我对整件事的看法完全错误吗?

I'm just learning the blackbery API, trying to follow the tutorials on the blackberry dev site, and I am a bit confused. In the interface tutorial they give the following instruction for making menu items...

private MenuItem _changeCapitol = new MenuItem("Change Capitol", 110, 10) 
{ 
    public void run() 
    { 
        if (displayed == 0) 
            _canadaCapitol = _input.getText(); 
        else if (displayed == 1) 
            _ukCapitol = _input.getText(); 
        else if (displayed == 2) 
            _usCapitol = _input.getText(); 
    } 
}; 

And that's all peachy and works for now. The issue is that the method used to create the MenuItem is deprecated. All of the tutorials appear to be for 4.0. I wanted to learn to do this the proper way so off I went to the 6.0 API Reference. I've tried to convert this to the current method but I can't get it quite right. Here is the closest that I have come...

private MenuItem _changecapitol = new MenuItem(new StringProvider("Change Capitol"), 110, 10);
changecapitol.setCommand(new Command(CapitolChange()));
class CapitolChange extends CommandHandler
{
    public void execute(ReadOnlyCommandMetadata metadata, Object context)
    {
        if (displayed == 0) 
            _canadaCapitol = _input.getText(); 
        else if (displayed == 1) 
            _ukCapitol = _input.getText(); 
        else if (displayed == 2) 
            _usCapitol = _input.getText();
    }

}

It seems as if there really should be something inside the brackets on the constructor but I can't imagine what that might be. If I understand the reference properly the functionality goes inside the CommandHandler, so I think I have that part right. The issue right now is that Eclipse is throwing an error on the line before the CapitolChange constructor.

changecapitol.setCommand(new Command(CapitolChange()));

I'm actually getting multiple errors on this line. One is a misplaced construct error, and the other claims that after "setCommand" I need an "=". This is nowhere in the API, and it would seem syntactically wrong. I'm calling a method and not assigning a value. Right? No? Am I just completely wrong on the whole thing?

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

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

发布评论

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

评论(2

半寸时光 2024-11-22 20:47:56

您使用了错误的变量,您使用“_changecapitol”创建了 MenuItem 并将其与此changecapitol 一起使用。更正拼写错误并检查错误。

You are using wrong variable, you create MenuItem with "_changecapitol" and using it with this changecapitol. correct the typo and check the errors.

给不了的爱 2024-11-22 20:47:56

我认为编译错误是由分配命令的位置不当引起的:

changecapitol.setCommand(new Command(CapitolChange()));

因为它被放置在 MenuItem 成员声明之后的类声明部分中的某个位置。
请尝试在其他地方分配命令,也许在屏幕构造函数中。

I think compile error is caused by improper place to have command assigned:

changecapitol.setCommand(new Command(CapitolChange()));

since it is placed somewhere in class declaration part right after MenuItem member declaration.
Please try to assign command elsewhere, maybe in screen constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文