Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Retrieving Text off of a button

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

Posts: 4007
  • 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

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.

You know it is dark times when the trees riot. I think this tiny ad is their leader:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic