import javax.swing.*; // Need this to reach Swing components import java.awt.*; // Need this to reach FlowLayout import java.awt.event.*; // Need this for listeners and events /** * HW 9 - This assignment is extra credit * * This class will create a DLLSoundElement linked list as well * as an interface to manipulate a list of songs. * * @author Brian O'Connor **/ public class JukeBox extends JFrame { /** * The start of the doubly linked list **/ private DLLSoundElement root; /** * The menu bar with File, Options, and Help **/ private JPanel outputPanel = new JPanel(); /** * The output label initialized to "Welcome to JukeBox **/ private JLabel output = new JLabel(); /** * The menu bar with: file, options and help drop-downs **/ private JMenuBar menu = new JMenuBar(); /** * The file dropdown **/ private JMenu file = new JMenu("File"); /** * The Options dropdown **/ JMenu options = new JMenu("Options"); /** * The help dropdown **/ JMenu help = new JMenu("Help"); /** * This method will set up a Doubly Linked List using the root variable * * Complete this method **/ public void setUp() { addButtons(); open(); } /** * This method will take in a sound parameter and create a DLLSoundElement and add it to the end of the playlist * * Complete this method * * @param s Sound the song that will be added to the end of the list **/ public void addSong(Sound s) { } /** * This method will play the current song in the play list * * Complete this method **/ public void playCurrent() { } /** * This method will remove the current song from the playlist and move to the previous song. If the song is the first in the playlist, don't remove it! * * Complete this method **/ public void removeCurrentSong() { } /** * This method will add buttons to the gui interface * * Complete this method **/ public void addButtons() { } /** * This method adds the menu items to the frame and opens the gui * * No need to edit. **/ public void open() { // Set up the add song menu item under the file menu drop down JMenuItem addSong = new JMenuItem("Add Song To List"); addSong.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String fileTemp = FileChooser.pickAFile(); Sound s; if (fileTemp != null) { if (fileTemp.endsWith(".wav")) { s = new Sound(fileTemp); if (s != null) { addSong(s); } } else { JOptionPane.showMessageDialog(null, "Please only select Wave files.", "alert", JOptionPane.ERROR_MESSAGE); } } } } ); file.add(addSong); // Set up the remove song menu item under the file menu drop down JMenuItem removeSong = new JMenuItem("Remove Song From List"); removeSong.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { removeCurrentSong(); } } ); file.add(removeSong); // Set up the remove song menu item under the file menu drop down JMenuItem close = new JMenuItem("Exit"); close.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); file.add(close); // Set up the play menu item under the options menu drop down JMenuItem playOption = new JMenuItem("Play"); playOption.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { playCurrent(); } } ); options.add(playOption); // Set up the play menu item under the options menu drop down JMenuItem playAllOption = new JMenuItem("Play All"); playAllOption.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { //current.playFromStart(); } } ); //options.add(playAllOption); // Set up the play menu item under the options menu drop down JMenuItem playFromHereOption = new JMenuItem("Play All From Here"); playFromHereOption.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { //current.playFromMeOn(); } } ); //options.add(playFromHereOption); // Set up the help menu item under the help menu drop down JMenuItem helpOption = new JMenuItem("Help"); helpOption.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] opts = { "OK"}; JOptionPane.showOptionDialog(null, "Adding Songs:\n\tTo add a song to the playlist, simply select File -> Add Song To List and select the file which you would like to add.\n\nRemoving Songs:\n\tTo remove a song from the playlist, simply select File -> Remove Song From List and the current song will be removed from the list. \nNote: you cannot remove the first song.\n\n\tFor more information please see the source code in myJukeBox.java in your javasource directory.", "Help", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opts, opts[0]); } } ); help.add(helpOption); // Set up the about menu item under the help menu drop down JMenuItem aboutOption = new JMenuItem("About"); aboutOption.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] opts2 = { "OK"}; JOptionPane.showOptionDialog(null, "myJukeBox was programmed by:\n\nBrian O\'Connor\n\nfor use in Georgia Institute of Technology\'s Computer Science course 1316", "About", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, opts2, opts2[0]); } } ); help.add(aboutOption); // add the menu drop downs to the jmenu menu.add(file); menu.add(options); menu.add(help); output = new JLabel("Welcome to JukeBox"); outputPanel.add(output); this.getContentPane().add(outputPanel, BorderLayout.SOUTH); // Set Up the frame this.setPreferredSize(new Dimension(600, 200)); this.pack(); setTitle("JukeBox"); setJMenuBar(menu); this.setVisible(true); this.show(); } }