BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-20-2011, 03:47 PM   #1
jordanzed
New Member
 
Join Date: Oct 2011
Model: 8530
PIN: N/A
Carrier: Koodo
Posts: 1
Default Custom BitmapButtonField not quite working out

Please Login to Remove!

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.
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads for: Custom BitmapButtonField not quite working out
Thread Thread Starter Forum Replies Last Post
want to assign custom ringtone, but not message alert... andrewbashuk General 9700 Series Discussion - Bold 2 0 02-24-2010 12:14 PM
Location API not working for custom/third-party applications nikhilbelsare Developer Forum 1 02-26-2009 10:39 AM
Blackberry Storm 9500 on AT&T, working except gqstatus05 General 9500 Series Discussion - Storm 5 01-30-2009 07:35 PM
Mic not working... FijiParisi General 8100 Series Discussion - Pearl 5 01-20-2007 12:20 PM
TMobile My Faves Custom Ring Tones Not Working! Ugh! fruitfly General 8100 Series Discussion - Pearl 5 01-14-2007 12:25 PM


OEM Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5 picture

OEM Dell XPS 8910 8920 8930 Alienware Aurora R5 R6 R7 Front Cooling Fan 7M0F5

$14.63



DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X  - Made By DELL picture

DELL 330-6581 3306581 725-10229 OEM LAMP FOR 1510X 1610HD 1610X - Made By DELL

$39.98



NEW VESA ADAPTER PLATE FOR DELL E-SERIES MONITORS - OEM picture

NEW VESA ADAPTER PLATE FOR DELL E-SERIES MONITORS - OEM

$6.00



Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008 picture

Dell OEM Latitude Rugged Extreme 7404 Left and Right Mouse Buttons 00008

$5.95



Genuine OEM Dell 2375 B2375dnf B2375dfw 110V Fuser fixing N41P2 sku 724-BBCI picture

Genuine OEM Dell 2375 B2375dnf B2375dfw 110V Fuser fixing N41P2 sku 724-BBCI

$94.99



NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL  picture

NEW DELL OEM REPLACEMENT PROJECTOR LAMP FOR 4220 4320 GENUINE ORIGINAL

$198.22







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.