开发者

Display sequence of words on BlackBerry screen

开发者 https://www.devze.com 2023-02-14 13:08 出处:网络
I have ten words in a string array.As an example: {\"A B\",\"C D\",\"E F\",\"G H\"......}. I have to display these words in succession, holding each word on screen for 2 seconds. With each new word di

I have ten words in a string array. As an example: {"A B","C D","E F","G H"......}. I have to display these words in succession, holding each word on screen for 2 seconds. With each new word displayed, the font size needs to get smaller开发者_Go百科 as well.

How do I do this on a BlackBerry?


You can use a Timer to control the timing:

import java.util.Timer

int index;
String[] words;

...

TimerTask task = new TimerTask() {
    public void run()
    {
         // TODO: Check the bounds and kill the timer when we're done.

         // Invoke the code in the UI Thread
         UiApplication.getUiApplication().invokeLater(new Runnable() {
             public void run()
             {
                // Code to enumerate and concat the string...
             }
          });
     }
 };

timer timer = new Timer();
timer.scheduleAtFixedRate(task, 0, 2000);

To change font size:

// in the class body:
final int minFontSize = 5;
int maxFontSize = minFontSize + words.length();

// in the timer's run method:
net.rim.device.api.ui.Font defaultFont = this.getFont();
net.rim.device.api.ui.Font myFont = defaultFont.derive(0, maxFontSize - index)

// change the font of the ui control
field.setFont(myFont);

I haven't checked the code to see if it compiles, but I hope you get the idea.

0

精彩评论

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

关注公众号