I get what you said, and unfortunately Java lacks the eval() function that could be used for that. You really should do:
unless you absolutely must be able to change it, in which case you could do:Code:JButton cb0 = new JButton("yes"); JButton cb1 = new JButton("no"); JButton cb2 = new JButton("maybe");
If you really are needing to do it in an array, you could always create an array of buttons:Code:cb0.setText("yes");
If you have a good reference guide, this should be covered in it. If not, I recommend Java: How to Program by Deitel & Deitel.Code:JButton[] btnarray; String[] btnlabels = {"yes", "no", "maybe"}; for (int i=0; i < btnlabels.length(); i++) { btnarray[i] = new JButton(btnlabels[i]); }




Reply With Quote