This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

components inside array..?

 
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 300 labels declared and initialised which is damn annoying with hard coded.

the labels are green color in background, so i want them to be red color if it get clicked by mouse.

the problem is i dont want to hard code it all in the mouseClicked() method....300 labels which is quite alot.

is it a easier way to do it or i just have to hard code it 1 by 1?
i was thinking of put all JLabel component into array, and use for loop to setBackground to red color;
like that i dont have to use type "setBackground" again and again to each label..

here is the code:
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just checked on one website,


could this work??
i can't try it because im in cyber cafe. But i will try it when i home.
If anyone knows earlier, please let me know....
thank you.
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reasonably simple like this
(change 100 to 300, and modify gridlayout specs)



[EDIT] remove extends JFrame
[ October 04, 2006: Message edited by: Michael Dunn ]
 
Nicky Eng
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you.
i will try it later i home.

thanks again.
 
reply
    Bookmark Topic Watch Topic
  • New Topic