スタックから作成されたボタンのグループをリッスンするアクション コマンド/アクションをプログラムに割り当てる方法に頭を悩ませています。ボタンは、テキスト ファイルの行から作成されます。
public void getLaunchButtons(){
File list = new File("resources/programs.txt");
String line = null;
try{
FileReader fr = new FileReader(list);
BufferedReader br = new BufferedReader(fr);
buttons = new Stack<Button>();
while((line = br.readLine()) != null){
buttons.push(new Button(line));
add(buttons.pop());
}
br.close();
}
catch(Exception ex){
}
}
作成したボタンにアクション リスナーを割り当てるにはどうすればよいですか? 私の全体的な目標は、クリックするとそのボタンに関連付けられたプログラムを起動するボタンを作成することです。ユーザーは、プログラム タイトル (ボタン タイトル) とディレクトリを起動するプログラム (ボタン アクション コマンド) に追加できます。