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


Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White picture

Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White

$39.95



Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod picture

Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod

$45.00



Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel picture

Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel

$56.41



Vintage  Rainbow Logo Apple Post-It Sticky Notes 4

Vintage Rainbow Logo Apple Post-It Sticky Notes 4" Rare computer collectible

$39.99



VINTAGE 1994 Apple Black Toner Laser Writer Cartridge M 2473 G/A NEW SEALED picture

VINTAGE 1994 Apple Black Toner Laser Writer Cartridge M 2473 G/A NEW SEALED

$25.95



Vintage Red Apple Six Drawer Storage Organizer File Cabinet  picture

Vintage Red Apple Six Drawer Storage Organizer File Cabinet

$35.00







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