File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JButton Syntax Question

 
Lonnie Wood
Greenhorn
Posts: 15
Chrome
  • 0
  • Mark post as helpful
  • send pies
  • 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,
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int a = array[1][2];
String s = "";
s = Integer.toString(a);

Works Great now.

Thanks.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic