I have almost managed to get my program working, but there is still one last bit I am having trouble with. I do not believe anybody has asked this question yet, because I am trying to select a JButton according to an array value which has been randomly selected. I generated one hundred JButtons on a grid, and I want to randomly select twenty for changing their text. Problem is, the text is not changing! So I am thinking I have not really selected any buttons. My problem code is as follows:
for (int i = 0; i < 20; i++)
{
Random randomRow = new Random(10);
Random randomColumn = new Random(10);
if (button == buttons[randomRow.nextInt(10)+1][randomColumn.nextInt(10)+1])
{
button.setText("treasure");
}
}
Aucun commentaire:
Enregistrer un commentaire