• 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

JButton Syntax Question

 
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm trying to build a panel that has nine buttons. Each button will need to show the value of an item in an array. So I built my array and tried to set the value of Button2 with the following code.


When compiling I get the error:
cannot find symbol
symbol : constructor JButton(int)
location: class javax.swing.JButton

If I substitute


It adds the button with the text Button 2.

Is there a different syntax that I should be using to equate the text of the button to the value of the array?

I haven't started building the Listeners and ActionPerformed yet, do I need that before this will work?

Thanks,
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're trying to call the constructor with an int as parameter. That constructor doesn't exist. You want to call it with a String. So the solution is to create a String from that int.
 
Lonnie Wood
Greenhorn
Posts: 15
Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
int a = array[1][2];
String s = "";
s = Integer.toString(a);

Works Great now.

Thanks.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Lonnie Wood wrote: . . ..

The initial assignment to "" is unnecessary. It's eitherorYou might do well to look at the String#valueOf method, too.
 
reply
    Bookmark Topic Watch Topic
  • New Topic