2009-09-02 12 views
5

私は1つのラベルフィールドと、赤、黄、青の3つのボタンを持っています。赤いボタンをクリックすると、ラベルフィールドのフォントの色が赤に変わります。同様に黄色のボタンをクリックすると、フォントの色が黄色に変わります。同様に、ボタンの色に応じて、フォントの色はラベルフィールドで変更する必要があります。ブラックベリーラベルフィールドのフォント色を動的に変更する方法は?

誰でもこの方法を教えてもらえますか? labelFieldプロパティで

答えて

13

フォントの色を簡単にsuper.paint前にペイントイベントにgraphics.setColorを設定することによって維持されている:

class FCLabelField extends LabelField { 
     public FCLabelField(Object text, long style) { 
      super(text, style); 
     } 

     private int mFontColor = -1; 

     public void setFontColor(int fontColor) { 
      mFontColor = fontColor; 
     } 

     protected void paint(Graphics graphics) { 
      if (-1 != mFontColor) 
       graphics.setColor(mFontColor); 
      super.paint(graphics); 
     } 
    } 

    class Scr extends MainScreen implements FieldChangeListener { 
     FCLabelField mLabel; 
     ButtonField mRedButton; 
     ButtonField mGreenButton; 
     ButtonField mBlueButton; 

     public Scr() { 
      mLabel = new FCLabelField("COLOR LABEL", 
        FIELD_HCENTER); 
      add(mLabel); 
      mRedButton = new ButtonField("RED", 
        ButtonField.CONSUME_CLICK|FIELD_HCENTER); 
      mRedButton.setChangeListener(this); 
      add(mRedButton); 
      mGreenButton = new ButtonField("GREEN", 
        ButtonField.CONSUME_CLICK|FIELD_HCENTER); 
      mGreenButton.setChangeListener(this); 
      add(mGreenButton); 
      mBlueButton = new ButtonField("BLUE", 
        ButtonField.CONSUME_CLICK|FIELD_HCENTER); 
      mBlueButton.setChangeListener(this); 
      add(mBlueButton); 
     } 

     public void fieldChanged(Field field, int context) { 
      if (field == mRedButton) { 
       mLabel.setFontColor(Color.RED); 
      } else if (field == mGreenButton) { 
       mLabel.setFontColor(Color.GREEN); 
      } else if (field == mBlueButton) { 
       mLabel.setFontColor(Color.BLUE); 
      } 
      invalidate(); 
     } 
    } 
+0

おかげcoldice.Itの便利 – Kumar

+0

どういたしまして! –

関連する問題