Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes JButton Syntax Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JButton Syntax Question" Watch "JButton Syntax Question" New topic
Author

JButton Syntax Question

Lonnie Wood
Greenhorn

Joined: Feb 16, 2011
Posts: 15

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

Joined: Oct 25, 2008
Posts: 2700

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.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Lonnie Wood
Greenhorn

Joined: Feb 16, 2011
Posts: 15

int a = array[1][2];
String s = "";
s = Integer.toString(a);

Works Great now.

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
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
 
subject: JButton Syntax Question
 
Similar Threads
cannot get stuff to repaint - please help
What is the best way to create GUI components- in-line, methods, inner classes or separate classes
How to refresh the JButton text among other things.
ScrollBar Problem
Swing simple