Please consult the program once

See once this program...

When I press the button will not change the color of the string...

package com.menuitems;

import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.component.RichTextField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

public class MenuScreen extends MainScreen {
    String string = "color will changed when u press the button";

    HorizontalFieldManager hFieldManagerTop;
    VerticalFieldManager vFieldManagerBottom;

    public MenuScreen() {
        final MyTextFiled myTextFiled ;
        hFieldManagerTop = new HorizontalFieldManager();
        vFieldManagerBottom = new VerticalFieldManager();

        myTextFiled = new MyTextFiled();
                myTextFiled.setText(string);

        RadioButtonGroup radioButtonGroup = new RadioButtonGroup();
        final RadioButtonField radioButtonField = new RadioButtonField("red", radioButtonGroup,true);
        final RadioButtonField radioButtonField1 = new RadioButtonField("green", radioButtonGroup, false);
        final RadioButtonField radioButtonField2 = new RadioButtonField("blue", radioButtonGroup, false);

        radioButtonGroup.setChangeListener(new FieldChangeListener() {

            public void fieldChanged(Field field, int context) {

                    if(radioButtonField.isSelected())
                    {
                        myTextFiled.setColor(Color.RED);
                    }
                    else if (radioButtonField1.isSelected())
                    {

                        myTextFiled.setColor(Color.GREEN);
                    }
                    else{

                        myTextFiled.setColor(Color.BLUE);
                    }

            }
        });

        hFieldManagerTop.add(myTextFiled);

        vFieldManagerBottom.add(radioButtonField);
        vFieldManagerBottom.add(radioButtonField1);
        vFieldManagerBottom.add(radioButtonField2);

        add(hFieldManagerTop);
        add(new SeparatorField());
        add(vFieldManagerBottom);

        }

}
    class MyTextFiled extends RichTextField{
        int color ;

        protected void paint(Graphics graphics) {
            graphics.setColor(color);
            super.paint(graphics);
        }

        void setColor(int color){
            this.color = color;
        }

        private int getColor(){
            return this.color;
        }
    }
   class MyTextFiled extends RichTextField{      int color ;

  protected void paint(Graphics graphics) {

          graphics.setColor(color);         super.paint(graphics);        }

      private void setColor(int color){         this.color = color;                        invalidate();        }

      private int getColor(){           return this.color;        } }

Try this one.

------------------------------------------------------------------------------------
Kudo press to say thank you to the developer.
Also, press accept it as a button when you got the Solution.

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for