Javaでスライドパズルを作ろうとしています。今、私は少し問題があります。クリックしたボタンのインデックスを知りたいArrayList
.
ArrayList<JButton>
ボタンには多数の が含まれています。JButton
各ボタンに ActionListener を追加してから、 this に配置しましたArrayList
。
私は何を間違っていますか?
参照としていくつかのコードを次に示します。
public void actionPerformed(ActionEvent ae)
{
if (buttons.contains(ae.getSource()) == true)
{
int click = buttons.indexOf(ae.getSource()); // <--- What's wrong with this?
System.out.println(click); /* I checked the index I got by printing
it out as a test, and it always gives
me the Integer '0', even if I clicked
the 9th Button for example. */
}
else
{
System.out.println("No click");
}
}