黑莓主屏幕上的股票行情

发布于 2024-11-18 15:51:31 字数 167 浏览 4 评论 0原文

我正在为黑莓设备构建一个应用程序,它将在主屏幕上显示一个股票行情。我进行了很多搜索但找不到解决方案。

我尝试过在固定的时间间隔后更新背景图像,但这使得手机速度非常慢。我不是主题开发人员,但尝试过,但再次失败。我想从我的应用程序中更新股票代码的文本。

请帮助我,我真的被困在这里了。提前致谢

I am building an application, for a Blackberry device, which will show a ticker on the home screen. I have searched a lot but couldn't find a solution.

I have tried updating the background image after fixed interval, but that makes the phone very slow. I am not a theme developer but tried it and failed again. I want to update the ticker's text from within my application.

Please help me, i am really stuck here. Thanks in advance

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

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

发布评论

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

评论(1

苦妄 2024-11-25 15:51:31

下面的代码可以让您更深入地了解股票代码
只需为下面的类创建一个对象并传递所需的参数即可。那会让你的工作完成。我猜:)

import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;

public class TickerField extends Field {
        String text;
        static final int screenWidth = Display.getWidth();
        int offset;
        private Timer timer = new Timer();
        final int delay = 30;
        private static int fontH = Font.getDefault().getHeight();
        private int w;
        private int h;
        private int bgColor = Color.WHITE;
        public TickerField(String text, int width, int height) {
                this.text = text;
                w = width;
                h = height;
                offset = w;
                final int textWidth = Font.getDefault().getAdvance(text);

                //schedule and start timertask 
                TimerTask timerTask = new TimerTask() {
                        public void run() {
                                offset--;
                                if (offset + textWidth == 0) {
                                        offset = screenWidth;
                                }
                                invalidate();
                        }
                };
                timer.scheduleAtFixedRate(timerTask, delay, delay);
        }
        public TickerField(String text) {
                this(text, screenWidth, fontH);
        }
        public TickerField(int width, int height) {
                this("", width, height);
        }
        public TickerField() {
                this("", screenWidth, fontH);
        }
        //set ticker text
        public void setText(String text) {
                this.text = text;
        }
        //get ticker text
        public String getText() {
                return text;
        }
        // implement layout to give specific arrangement to this field
        // Invoke Math.min() to return the smaller of the user specified w and h,
        // and the preferred width and height of the field.
        protected void layout(int width, int height) {
                width = Math.min(w, getPreferredWidth());
                height = Math.min(h, getPreferredHeight());
                setExtent(width, height);
        }
        // Implement the paint() to redraw the field with different
        // offset controlled by timer task.That will give the
        // ticker effect.
        protected void paint(Graphics graphics) {
                graphics.drawText(text, offset, 0);
        }

        public void setBgColor(int bgColor) {
                this.bgColor = bgColor;
        }
        //Implement the paintBackground() method to change the 
        //background color of the field.
        protected void paintBackground(Graphics g) {
                g.setBackgroundColor(bgColor);
                g.clear();
                super.paintBackground(g);
        }


        // Implement getPreferredWidth() and getPreferredHeight(), using the
        // screenWidth and font height to make sure that the ticker does not exceed
        // the dimensions of the
        // component.
        public int getPreferredWidth() {
                return screenWidth;
        }
        public int getPreferredHeight() {
                return fontH;
        }

}

快乐编码:)

the code below could give you more insight into the Ticker
Just create an object to the class below and pass the required arguments. That would make your job done. I guess :)

import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;

public class TickerField extends Field {
        String text;
        static final int screenWidth = Display.getWidth();
        int offset;
        private Timer timer = new Timer();
        final int delay = 30;
        private static int fontH = Font.getDefault().getHeight();
        private int w;
        private int h;
        private int bgColor = Color.WHITE;
        public TickerField(String text, int width, int height) {
                this.text = text;
                w = width;
                h = height;
                offset = w;
                final int textWidth = Font.getDefault().getAdvance(text);

                //schedule and start timertask 
                TimerTask timerTask = new TimerTask() {
                        public void run() {
                                offset--;
                                if (offset + textWidth == 0) {
                                        offset = screenWidth;
                                }
                                invalidate();
                        }
                };
                timer.scheduleAtFixedRate(timerTask, delay, delay);
        }
        public TickerField(String text) {
                this(text, screenWidth, fontH);
        }
        public TickerField(int width, int height) {
                this("", width, height);
        }
        public TickerField() {
                this("", screenWidth, fontH);
        }
        //set ticker text
        public void setText(String text) {
                this.text = text;
        }
        //get ticker text
        public String getText() {
                return text;
        }
        // implement layout to give specific arrangement to this field
        // Invoke Math.min() to return the smaller of the user specified w and h,
        // and the preferred width and height of the field.
        protected void layout(int width, int height) {
                width = Math.min(w, getPreferredWidth());
                height = Math.min(h, getPreferredHeight());
                setExtent(width, height);
        }
        // Implement the paint() to redraw the field with different
        // offset controlled by timer task.That will give the
        // ticker effect.
        protected void paint(Graphics graphics) {
                graphics.drawText(text, offset, 0);
        }

        public void setBgColor(int bgColor) {
                this.bgColor = bgColor;
        }
        //Implement the paintBackground() method to change the 
        //background color of the field.
        protected void paintBackground(Graphics g) {
                g.setBackgroundColor(bgColor);
                g.clear();
                super.paintBackground(g);
        }


        // Implement getPreferredWidth() and getPreferredHeight(), using the
        // screenWidth and font height to make sure that the ticker does not exceed
        // the dimensions of the
        // component.
        public int getPreferredWidth() {
                return screenWidth;
        }
        public int getPreferredHeight() {
                return fontH;
        }

}

Happy Coding :)

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