开发者

Blackberry API / MenuItems

开发者 https://www.devze.com 2023-03-14 01:50 出处:网络
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 i

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.

changecap开发者_运维技巧itol.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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号