Java me 我是j2me的初学者。在j2me的Ticker函数中,如何在单个Ticker中应用不同的颜色?
*我正在为诺基亚s40设备开发一个j2me Lwuit项目。我对自动售票机有一些问题。我只为tiker应用了一种颜色。但我希望为单个ticker应用不同的颜色。这是我的ticker代码:Java me 我是j2me的初学者。在j2me的Ticker函数中,如何在单个Ticker中应用不同的颜色?,java-me,colors,lwuit,ticker,Java Me,Colors,Lwuit,Ticker,*我正在为诺基亚s40设备开发一个j2me Lwuit项目。我对自动售票机有一些问题。我只为tiker应用了一种颜色。但我希望为单个ticker应用不同的颜色。这是我的ticker代码: Ticker tick; String tickerText=" "; Label lblIndice=new Label(); Label ticker=new Label(""); for (int i = 0; i < tickerIn
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);*
Ticker滴答声;
字符串tickerText=“”;
Label lblIndice=新标签();
标签标记器=新标签(“”);
对于(int i=0;i0)
{
ticker.getStyle().setFgColor(0X2E9F37);
}
其他的
{
ticker.getStyle().setFgColor(0XFF0000);
}
lblChange.setText(“+”(“+val+”);
}
System.out.println(“TICKER==”+tickerText);
ticker.setText(tickerText);
ticker.getStyle().setFont(Font.createSystemFont(Font.FACE\u MONOSPACE,Font.STYLE\u BOLD,Font.SIZE\u SMALL));
startTicker股票代码(50,正确)*
LWUIT不支持标签的不同颜色(因此为ticker),因为这需要相当多的处理
不过,在LWUIT中从头开始实现一个ticker是相当容易的。仅衍生标签并替代绘制,如下所示:
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());
}
LWUIT不支持标签的不同颜色(因此为ticker),因为这需要相当多的处理 不过,在LWUIT中从头开始实现一个ticker是相当容易的。仅衍生标签并替代绘制,如下所示:
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());
}