0
자바에서 슬라이드 퍼즐을 만들려고합니다. 이제 조금 문제가 있습니다. 클릭 한 버튼의 인덱스를 알고 싶습니다.이 버튼은 ArrayList
에 있습니다.ArrayList에서 ActionEvent의 소스를 얻는 방법
ArrayList<JButton>
버튼이 있으며 JButton
이 포함되어 있습니다.이 버튼을 넣기 전에 각 버튼에 ActionListener를 추가했습니다. 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");
}
}