referencing a JButton by name
Hi to all,
I'm new in Java, doing simple Yamb (Yahtzee) app for a class in Java programming I attend...
Anyhow, this is what I have (a 2D grid of buttons):
int row = 1;
int column = 1;
for(int i=0; i<24; i++){
if(i%4==0){
if(i!=0){
this.add(new JLabel(""),c);
c.gridy++;
row++;
column= 1;
}
this.add(new JLabel("" +j++, JLabel.CENTER),c);
}
JButton b = new JButton(" ");
b.setName(column + "_" + row);
b.setMnemonic(KeyEvent.VK_E);
b.setActionCommand(column + "_" + row);
b.addActionListener(this);
this.add(b,c);
column++;
}
.
.
.
public void actionPerformed(ActionEvent e) {
String str = new String(e.getActionCommand());
tf.setText(str);
JButton btnSource = (JButton)e.getSource();
btnSource.setText(str);
btnSource.setEnabled(false);
}
OK, so this works...what I would like to be able to do is when I press a button, I get its name i.e. "1_1"...I can tokenize that and get a column and a row from it...so I would like to increment, let's say a row value and reference to button with that name so I can enable/disable it...
I need something like eval(String JButton.Name).enable(false)...
Can this be done without beans? Referencing a JButton instance by its name?
Thanks for listening (reading)...
Cheers,
Alen

