私は右の作業私のボタンを持っている、と私はこのような各ボタンにリスナーです:あなたは、リスナーが呼び出される見ることができる、と私は「どのボタンを知りたいとここでクリックされたボタンはどのようにして知ることができますか?
for(int i = 0; i <= 25; ++i) {
buttons[i] = new Button(Character.toString(letters[i]));
buttons[i].addActionListener(actionListener);
panel1.add(buttons[i]);
}
mをクリックします。それを行う方法はありますか?
ActionListener actionListener = new ActionListener() {
public void actionPerformed(ActionEvent actionEvent) {
System.out.println(actionEvent.getSource());
}
};
配列内のボタンを見つけるには何らかの方法が必要です。
キャストボタンに最初のソース、ラベルの取得((ボタン)actionEvent.getSource())。getLabel()... – Rudy