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 / May 2007

Tip: Looking for answers? Try searching our database.

Using a method to change a buttons color

Thread view: 
KDawg44 - 29 May 2007 03:29 GMT
Hi,

I have a series of buttons name

btnPXxY where X and Y are numbers ranging from 0 to 10 in a grid of
buttons.  For example, a button name btnP0x0 and another named btnP0x1
etc.

When the buttons are pressed I want to pass integers x and y to a
method.  This method is going to a bunch of things with these numbers
but one thing i would like to do would be to change the color of the
button corresponding to this.

How can I pass the variables x and y into another variable name?  is
this possible?  something along the lines of:

btnP + varX + x + varY. bgcolor = red.

Thanks for any suggestions.  I am HOPING that I do not have to pass
the button object into the function since I will have to change a
bunch of code for these buttons.

Thanks.
Brandon McCombs - 30 May 2007 01:46 GMT
> Hi,
>
[quoted text clipped - 3 lines]
> buttons.  For example, a button name btnP0x0 and another named btnP0x1
> etc.

Why not create a 10x10 array to hold the pointers to the buttons? The
Object that btnArray[0][1] would point to would be the button at that
grid location.

> When the buttons are pressed I want to pass integers x and y to a
> method.  This method is going to a bunch of things with these numbers
> but one thing i would like to do would be to change the color of the
> button corresponding to this.

Each button can be its own listener and change its own color by waiting
for the Action Event to be generated when a user clicks it. By doing it
that way you don't need to know what the x and y values are. Each button
changes itself and would implicitly know what to change.

> How can I pass the variables x and y into another variable name?  is
> this possible?  something along the lines of:
>
> btnP + varX + x + varY. bgcolor = red.

I personally don't understand what the above line is supposed to do.

> Thanks for any suggestions.  I am HOPING that I do not have to pass
> the button object into the function since I will have to change a
> bunch of code for these buttons.
>
> Thanks.

hope that helps


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.