• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving Text off of a button  RSS feed

 
Ryan O'Neill
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to check to see if the button has anything on it.
Line 81 says incompatible types: JButton cannot be converted to String ')' expected ';' expected


 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ryan,

you seem to be struggling a lot to get the button that has been clicked
upon.

So I like to give you two ways to simplify identifying this button.

My favorite way is to subclass Button, although I usually use JLabels
for such things.
For instance:
Then, in your actionListener, all you need to do is


Of course, in your setup, you need to create these 'MyButton's,
for instance:

Another way is to store the JButton, (r, c) - combination in a
HashMap<JButton, int[]>. In your actionListener, you then
simply say

But back to your question: look at lines 85 and 88.
This is also the way to retrieve the text on a button.

Beware though, that it is easier to use a decent array int[3][3]
as a board, and to use that for the game logic.

Greetz,
Piet
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!