I am rather new at Java. Here's the problem...
I have tons of JButtons in my class. In my code I am using the
following methods for each and every button:
setFont
setBackground
setForeground
setBounds
addActionListener
I want to create a class where I can pass the button name and all the
parameters needed for the 5 methods above and set everthing there and
just call this new class after each button has been instantiated.
This would greatly reduce the size of my program. But is this
possible? I have a feeling there's a very easy answer but it escapes
me.
Thank you very much
G.Schiber
> I am rather new at Java. Here's the problem...
>
[quoted text clipped - 4 lines]
> setBackground
> setForeground
Those three are usually not good to call.
You're interfering with whatever look-and-feel the user has
installed/chosen.
> setBounds
Very very bad.
This probably means that you are not using a layout manager. This also
means that your program will not work properly on most computers other
than yours.
> addActionListener
This is one that should be called.
> I want to create a class where I can pass the button name and all the
> parameters needed for the 5 methods above and set everthing there and
> just call this new class after each button has been instantiated.
> This would greatly reduce the size of my program. But is this
> possible? I have a feeling there's a very easy answer but it escapes
> me.
Well, there are a few ways to address that (subclassing would not be one
of my choices), but instead...
... you should shouldn't be doing that.
Fill us in on the end goal of what you actually want to do (the ends),
instead of just how you think you can do it (the means), and we can
probably help more.
Remember, "make the text 12 point, and the button 20 pixels tall" is a
means, whereas "make the button show the text legibly" is a more proper
ends.