BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   Custom BitmapButtonField not quite working out (http://www.blackberryforums.com/showthread.php?t=254693)

jordanzed 10-20-2011 03:47 PM

Custom BitmapButtonField not quite working out
 
So I'm a new Java/BB developer, more familiar with PHP than anything. I haven't used Java in a while and made the decidedly ill-advised decision of relearning Java through the Blackberry JDE. I decided to start off with a 'simple' Italian card game. It's pretty messy as I just sort of threw it together as I ran into problems and solved them.



My plan was to show the 3 cards in your hand at the bottom, and have them focusable, and selectable. Once selected I want to take the card out of your hand, put it on the table, and change the bitmapField image.



I made a custom BitmapButton class that extends BitmapField, making it focusable, and overriding navigtionUnclick(). On nUnclick, it sends a notification to the FieldChangeListener. Problem is, I can't set everything to final, and therefore can't do anything with my buttons now. Is there another method to do what I'm trying to do? I've been searching and rewriting for days.



The only way I can refer to any outside objects or variables is to declare them final.



while(confusionStatus=="confused"){

confusionStatus="confused";

}



Anyways, here's the code for the BitmapButton:
Code:

/*
 * BitmapButton.java
 *
 * © <your company here>, <year>
 * Confidential and proprietary.
 */

package Briscola;

import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;

/**
 *
 */
public class BitmapButton extends BitmapField {
           
            private Bitmap normal;
            private Bitmap focus;
           
            BitmapButton(Bitmap bitmap, Bitmap focusImg){
                super(bitmap);
                normal = bitmap;
                focus = focusImg;
            }
           
            public boolean isFocusable() {
                return true;
            }
           
            public void onFocus(int direction){
                invalidate();
                setBitmap(focus);
            }
           
            public void onUnfocus(){
                super.onUnfocus();
                invalidate();
                setBitmap(normal);
            }
           
            protected void drawFocus(Graphics _g, boolean _on) {  /* do nothing */ }
       
            protected void paint(Graphics graphics)
            {
                graphics.setColor( 0xF2DE57 );
                super.paint(graphics);
            }
       
            protected boolean navigationUnclick(int status, int time) {
                fieldChangeNotify(0);
                return true;
            }
           
           
    }

And, here's the area in question:
Code:

/*-- Setup Playing Field --*/
                HorizontalFieldManager inPlay = new HorizontalFieldManager();
                BitmapField play1 = new BitmapField(Bitmap.getBitmapResource("Holder.png"));
                BitmapField play2 = new BitmapField(Bitmap.getBitmapResource("Holder.png"));
                BitmapField briskImg = new BitmapField(brisk.face);
                briskImg.setMargin(0,0,0,0);
                play1.setMargin(0,5,0,34);
                inPlay.add(briskImg);
                inPlay.add(play1);
                inPlay.add(play2);
                inPlay.setMargin(10,0,0,10);
                Play.add(inPlay);
               
                int Turn = 1; //P1 Turn               
               
                HorizontalFieldManager inHand = new HorizontalFieldManager();
                /**/one = new BitmapButton(P1.hand[0].face,P1.hand[0].focus);
                /**/two = new BitmapButton(P1.hand[1].face,P1.hand[1].focus);
                /**/three = new BitmapButton(P1.hand[2].face,P1.hand[2].focus);
                FieldChangeListener fcm = new FieldChangeListener() {
                      public void fieldChanged(Field field, int context) {
                        if(context==0){
                            if(field==one){
                                Dialog.alert("first card");
                            }
                            if(field==two){
                                Dialog.alert("second card");
                            }
                            if(field==three){
                                Dialog.alert("third card");
                            }
                        }
                      }
                };     
                one.setChangeListener(fcm);
                two.setChangeListener(fcm);
                three.setChangeListener(fcm);

I want to change the image of the BitmapButton pressed, as the card shouldn't be in your hand once it's been played obviously, as well as that of either play1 or play2, depending on who's turn it is.

The card game is Briscola if anyone is interested.


All times are GMT -5. The time now is 04:10 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.