开发者

I am beginner in j2me.In J2me Ticker function, How to apply differnt Color in Single Ticker?

*I am developing one j2me-Lwuit Project for Nokia s40 devices.I have some problem abuot ticker. I have apply Only one color for tiker.But i want differnt color to apply for single ticker.This is my code for Ticker:

       Ticker tick;
        String tickerText=" ";
         Label lblIndice=new Label();
    Label ticker=new Label("");
    for (int i = 0; i < tickerIndiceData.size(); i++) 
        {
            tickerText +=" "+tickerIndiceData.elementAt(i).toString();
            tickerText +=" "+tickerValueData.elementAt(i).toString();
            tickerText +=" "+"("+tickerChangeData.elementAt(i开发者_开发技巧).toString()+")";
            lblIndice.setText(" "+tickerIndiceData.elementAt(i).toString());
            lblValue.setText(" "+tickerValueData.elementAt(i).toString());
            double val=Double.parseDouble(tickerChangeData.elementAt(i).toString());
            if(val>0)
            {
                ticker.getStyle().setFgColor(0X2E9F37);
            }
            else
            {
                ticker.getStyle().setFgColor(0XFF0000);
            }
            lblChange.setText(" "+"("+val+")");
        }
        System.out.println("TICKER==="+tickerText);
ticker.setText(tickerText);
        ticker.getStyle().setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL));
        ticker.startTicker(50, true);*


LWUIT doesn't support different colors for a label (hence ticker) since that would require quite a bit of processing.

Implementing a ticker from scratch in LWUIT is pretty easy though. Just derive label and override paint as such:

public void paint(Graphics g) {
    UIManager.getInstance().setFG(g, this);
    Style style = l.getStyle();
    Font f = style.getFont();
    boolean isTickerRunning = l.isTickerRunning();
    int txtW = f.stringWidth(text);

    // update this to draw two strings one with the color that's already set and the
    // other with the color you want
    g.drawString(getText(), getShiftText() + getX(), getY(),style.getTextDecoration());        
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜