我正在使用此代码从文本文件中加载 JmenuItems
FileInputStream wordsFile = new FileInputStream(signlink.findcachedir() + "/Playlist.div");
BufferedReader br = new BufferedReader(new InputStreamReader(wordsFile));
String[] favoriteSongs = new String[15];
for (int i = 0; i < favoriteSongs.length; i++) {
favoriteSongs[i] = br.readLine();
if (favoriteSongs[i] != null) {
System.out.println(favoriteSongs[i]);
JMenuItem song = new JMenuItem(favoriteSongs[i]);
song.addActionListener(this);
favorites.add(favoriteSongs[i]);
} else {
wordsFile.close();
break;
}
}
如何为 JmenuItems 添加操作