Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Nee Help!! JButton arrays action...  RSS feed

 
Sebastien Leclerc-Tittley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok my first post here and a question!!Im working on a project for school and I ust cant seem to find a way to do this.....My teacher want Lotto 6/49 apllication (you have 49 numbers choose 6)
so I made Jbutton array containing 49 buttons...my problem is that the teacher want the JButton to setVisible(false) when its clicked (made it and work) and that 6 numbers appear in a JTextArea after selecting them and the button sta is set back to setVisible(true)....this is my Action code for now ....



hope you guys can help me...sorry for my bad english
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't really need the for loop, since you know which button has been pressed via ae.getSource. Something as simple as
((JButton)ae.getSource).setVisible(false); would work.

Also, you can get the Button's text easy via the ActionEvent's getActionCommand() method.

I have to tell you that I disagree with your teacher. I'd have the button become disabled (setEnabled(false), not invisible after it has been pressed.

 
Sebastien Leclerc-Tittley
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply but my problem was not with the setVisible/Enable......its actually keeping the six buttons I clicked in an array and after that paste it in a JTextArea and then set them back to their original state...and I need to kepp the loop teacher asked for it....
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sebastien Leclerc-Tittley wrote:Thanks for the reply but my problem was not with the setVisible/Enable......its actually keeping the six buttons I clicked in an array and after that paste it in a JTextArea and then set them back to their original state...and I need to kepp the loop teacher asked for it....


It's probably not a good idea to make us guess where your problem is, but instead to be clear about it in your first post. Most of us can't read minds.

Anyway, you don't need to know which buttons have been pushed, but instead all you need to do is to know which numbers have been selected. You can get the number String by getting the button's action command as I showed above, parsing it into a number is trivial, and then place the number in an array or a collection such as an ArrayList. Then when you want to reset your buttons, don't worry about resetting just the affected buttons, reset them all. It won't take long for Java to do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!