Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / August 2003

Tip: Looking for answers? Try searching our database.

JButtons, JButtons, JButtons

Thread view: 
G.Schiber - 23 Aug 2003 02:57 GMT
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
Jon A. Cruz - 23 Aug 2003 18:42 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.