Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry® World™ Development

Reply
New Contributor
Posts: 5
Registered: ‎05-16-2011
My Device: 8900
My Carrier: Digicel

Bb hello world code

Hi

I just went thru the helloworld app yesterday. Today I went thru A11 UserInterface code and ran it on eclipse on my 8900 simulator but the buttons don't show up. Here's my code:

package UserInterfacePackage;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.Menu;
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;

/**
* A class extending the MainScreen class, which provides default standard
* behavior for BlackBerry GUI applications.
*/
public final class MyScreen extends MainScreen
{
   HorizontalFieldManager _fieldManagerTop;
   VerticalFieldManager _fieldManagerMiddle;
   HorizontalFieldManager _fieldManagerBottom;
   BitmapField _bitmap;
   Bitmap _canadaImage, _ukImage, _usImage;
   LabelField _label;
   BasicEditField _input;
   String _canadaCapital, _ukCapital, _usCapital, _capital;
   int displayed = 0;
/**
    * Creates a new MyScreen object
    */
   public MyScreen()
   {        
       // Set the displayed title of the screen       
       LabelField title = new LabelField("User Interface
Sample",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
       setTitle(title);

       //Managers
       //HorizontalFieldManager _fieldManagerTop;
       //VerticalFieldManager _fieldManagerMiddle;
       //HorizontalFieldManager _fieldManagerBottom;

       _fieldManagerTop = new HorizontalFieldManager();
       _fieldManagerMiddle = new VerticalFieldManager();
       _fieldManagerBottom = new HorizontalFieldManager();
       add(_fieldManagerTop);
       add(new SeparatorField());
       add(_fieldManagerMiddle);
       add(new SeparatorField());
       add(_fieldManagerBottom);

       //bitmaps
       //BitmapField _bitmap;
       //Bitmap _canadaImage, _ukImage, _usImage;

       _canadaImage = Bitmap.getBitmapResource("canada.png");
       _ukImage = Bitmap.getBitmapResource("uk.png");
       _usImage = Bitmap.getBitmapResource("us.png");
       _bitmap = new BitmapField();
       _bitmap.setBitmap(_canadaImage);
       _fieldManagerTop.add(_bitmap);

       // Capitals
       //LabelField _label;
       //BasicEditField _input;
       //String _canadaCapital, _ukCapital, _usCapital, _capital;
       _canadaCapital = "Ottawa";
       _ukCapital = "London";
       _usCapital = "Washington";
       _capital = _canadaCapital;
       _label = new LabelField("Please press a button!");
       _input = new BasicEditField("Capital (can be changed):", _capital);
       _fieldManagerMiddle.add(_label);
       _fieldManagerBottom.add(_input);

       //Buttons
       ButtonField canadaButton = new ButtonField("Canada");
       ButtonField ukButton = new ButtonField("  UK  ");
       ButtonField usButton = new ButtonField("  US  ");

       //add listeners to buttons
       FieldChangeListener listenerCanada = new FieldChangeListener(){
       public void fieldChanged(Field field, int context) {
       _bitmap.setBitmap(_canadaImage);
       _input.setText(_canadaCapital);
       displayed = 0;
       }
       };

       FieldChangeListener listenerUK = new FieldChangeListener(){
       public void fieldChanged(Field field, int context) {
       _bitmap.setBitmap(_ukImage);
       _input.setText(_ukCapital);
       displayed = 1;
       }
       };

       FieldChangeListener listenerUS = new FieldChangeListener(){
       public void fieldChanged(Field field, int context) {
       _bitmap.setBitmap(_usImage);
       _input.setText(_usCapital);
       displayed = 2;
       }
       };

       // assign listeners to buttons
       canadaButton.setChangeListener(listenerCanada);
       ukButton.setChangeListener(listenerUK);
       usButton.setChangeListener(listenerUS);

       // add buttons to the managers
       _fieldManagerBottom.add(canadaButton);
       _fieldManagerBottom.add(ukButton);
       _fieldManagerBottom.add(usButton);

   }
       protected void makeMenu(Menu menu, int instance) {
       menu.add(_changeCapital);
       menu.add(_close);
       }

       private MenuItem _changeCapital = new MenuItem("Change Capital", 110,
10){
       public void run(){
       if (displayed == 0)
       _canadaCapital = _input.getText();
       else if (displayed == 1)
       _ukCapital = _input.getText();
       else if (displayed == 2)
       _usCapital = _input.getText();
       }
       };

       private MenuItem _close = new MenuItem("Close", 110, 10) {
       public void run(){
       onClose();
       }
       };

       public boolean onClose() {
       Dialog.alert("Goobai");
       System.exit(0);
       return true;
       }
}

Anything strikes anyone as outta whack?