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

Java Development

Reply
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Custom BitmapButtonField not quite working out

I am looking back at the sample code given.

 

I can see you have Card objects, and the MainScreen which displays the 'Table'.   So in this code, it seems that the MainScreen should be responsible for listening to the changes and moving the cards

 

Given this, I think the code you have

Deck deck = new Deck(); //init. deck

...
Play.add(inHand);

 

actually belongs in the constructor of your Play screen.  This screen should know who the Players are and understand the interaction, not your UiApplication.  This ties in with this screen having the 'Table'. 

 

In the following code you are making the Object that displays one card responsible for listening to itself:

one.setChangeListener(one);

But the Object that listens for these changes has to be able to see the whole table.  It doesn't make sense for a Card to understand the Table. 

 

So I would change the change listener for the BitmapButtons to be the screen too.

And in fact, Your BitmapButtons, i would change (as I suggested above) so that they are actually given a default image (to display if they don't have a card) and potentially a card.  Then in their paint method I would display the card image if one was there or the default image. You will need to create removeCard and addCard method for this Object, so that it starts working like a Position on the Table.

 

Sorry i seem t be repeating myself here, but I think it is very useful to do the Object analysis before you start coding.  A good Object design will make the coding easy, because you know what interaction goes on between your Objects.  You appear to be trying to shoehorn a Position into a BitmapButton, when I think it would be easier for you create a more complicated Object that worked like a Position on the Table.  You've go a lot of this already, you seem to be stuck getting a UiComponent to do what you want, rather than constructing one that does what you want. 

 

I think I might be rambling, but I hope this helps. 

Please use plain text.
New Contributor
jordanzed
Posts: 7
Registered: ‎10-20-2011
My Device: Curve 8530
My Carrier: Koodo

Re: Custom BitmapButtonField not quite working out

That does help, thanks. There was some definite shoehorning here. I ran into it with a little more confidence than warranted :smileytongue: Back to the drawing board.

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Custom BitmapButtonField not quite working out

"I ran into it with a little more confidence than warranted "

 

Disagree.  I'm betting you have never been on a Object design course, and what you have done so far is good.  There is also a confidence thing, but that is the confidence to write your own Ui code.  Ui on BlackBerry is a dark art, something that I have never really got completely to grips with, I just fumble along.  Look to people like mreed and arkadyz if you want to speak to people who know UI.  Anyway, if you are not familiar with UI stuff it is much easier to take something you know and try to make it work. 

 

Good job so far.  yes you are going to redo it but you are doing so for the right reasons. 

Please use plain text.