Drawable Button question


#1

I’m trying to subclass DrawableButton, to override paintButton. I’d like to be able to access the drawable images held by the parent class, but out of 8 images, there are only 4 accessors.

Access to the ButtonStyle and edgeIndent members would also be great. Is there a way to get these values, or is DrawableButton not designed to be subclassed?

I know that there are some design philosophies at work here, but I wish
member variables were protected, not private, so subclasses could get them directly, or that there were accessor functions for all private member variables as a rule.


#2

Personally, I would say the sole purpose of DrawableButton is the paint stuff that it defines. What would you want to subclass it for? If you wanted to do anything more specific then you’d probably be better off just subclassing Button instead.


#3

Subclassing Button instead is a fair suggestion.

I was subclassing DrawableButton because my new button classes uses 4 different states that come from a binfile. Since DrawableButton already does that, if I could override PaintButton() to do some slightly different things, I would have been in business.

Unfortunately, I hit the problem outlined before: some of the variables used in PaintButton() are private to DrawableButton, and without accessor functions, so they can’t be used in derived classes.


#4

So I tried subclassing Button instead, and ran into other problems:

•I can’t override workOutState(), it’s private
•This means I can’t override mouseDown() and have it call workOutState() because it’s private.
•I could have mouseDown() call some other function similar to workOutState, but it would be handy if that new function could also return a ButtonState. Unfortunately the ButtonState enum is unavailable, as it’s private.

Now, granted, I may be trying to do something a little off the wall, which is to allow the disabled state to represent a latent state in which users can still click on a button, but without effect. Perhaps I’m better off trying to derive a new button class from Component…


#5