• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to add JButtons to an array

 
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

I have a GUI i have created a gui qith 16 JButtons

example of how i created them



they go from A1-A4 to D1-D4 ,four rows.
I would like to add the JButtons to an array, how should i go about it? i am guessing it is possible but maybe i am wrong?

i would like to make something like JButton[] rowA = JButton{A1,A2,A3,A4}; -----> i am really terrible whith Arrays!!

Thanks
Mike
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Suggest you get yourself a factory method.You would have to check the syntax, and that I have got the names of all the methods right. You can overload that method to your heart’s content. You can use Actions instead of Listeners.
 
mike ryan
Ranch Hand
Posts: 210
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Campbell,

Thanks for your response, that would be a good way to create the buttons, but i have already created them and want to have them in a list of rows.Maybe you missunderstood my question OR i don't understand your reply <--- (which is possible ;) ).

I am currently trying this with ArrayList



i will eventually need to test quite a few things in each row like if rowA doesn't equal an even number it will be false as well as if there are more than three of the same numbers beside eachother it will be false and so on,
i am thinking this will get really long with all the checks, maybe there is a better solution?

Thanks
Mike
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic