Your class is massive and it is missing other classes references.Though,I have put together an example for you. I am sure this will help you.
import java.awt.EventQueue;
public class SongPlayer {
private JFrame frmSongPlayer;
private List<String> songs;
private ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() instanceof JMenuItem) {
JMenuItem item = (JMenuItem) e.getSource();
// now
String url = "http://songs/" + item.getName();
System.out.println(url);
}
}
};
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
SongPlayer window = new SongPlayer();
window.frmSongPlayer.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public SongPlayer() {
try {
songs = FileUtils.readLines(new File(SongPlayer.class.getResource("/PlayList.txt").getPath()));
} catch (IOException e) {
e.printStackTrace();
}
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmSongPlayer = new JFrame();
frmSongPlayer.setTitle("Song player");
frmSongPlayer.setBounds(100, 100, 450, 300);
frmSongPlayer.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frmSongPlayer.getContentPane().setLayout(null);
JMenuBar songBar = new JMenuBar();
songBar.setBounds(10, 11, 101, 23);
frmSongPlayer.getContentPane().add(songBar);
JMenu song = new JMenu("Songs");
songBar.add(song);
for (String mp3song : songs) {
JMenuItem mntmNewMenuItem = new JMenuItem(mp3song);
mntmNewMenuItem.setName(mp3song);
mntmNewMenuItem.addActionListener(listener);
song.add(mntmNewMenuItem);
}
}
}
Above class will open Swing UI
with songs menu and the items are selected from Playlist.txt
file.When you click on the song,it generates appropriate url.