Dynamically accessing a button when I know the button number

ammoun

New Member
Nine \[code\]JButtons\[/code\] are declared as :\[code\]private javax.swing.JButton jButton1;private javax.swing.JButton jButton2;private javax.swing.JButton jButton3;private javax.swing.JButton jButton4;private javax.swing.JButton jButton5;private javax.swing.JButton jButton6;private javax.swing.JButton jButton7;private javax.swing.JButton jButton8;private javax.swing.JButton jButton9;\[/code\]I could have had a button array but it doesn't suit the application.During the program run I want to dynamically access a button when I know the button number.Like at some instance I want for button number \[code\]5\[/code\], \[code\]setText("X")\[/code\]. Is there any way I can do that ? A \[code\]JButton\[/code\] array would have solved the problem very easily by just doing :\[code\]buttonArray[5].setText("X")\[/code\]but as I told, it overall doesn't suit the application. Accessing a button by its number is one thing. If there is any other way to do this,please mention.
 
Back
Top