import java.awt.*; import java.awt.event.*; public class PlayListManager extends Frame { // Instance variables private PlayList model; // main PlayList private PlayList newPlayList; private String outFile; private List mainList; private List newList; public PlayListManager( String in, String out ) { super( "Play List Manager" ); // Taking of the data structures that will be storing our data try { this.model = PlayList.getSongsFromFile( in ); } catch ( java.io.IOException e ) { System.err.println( e.getMessage() ); System.exit( 1 ); } newPlayList = new PlayList(); // we'll be adding Songs to this PlayList outFile = out; // Creating a Panel to visualize the two PlayLists Panel listsPanel = new Panel(); listsPanel.setLayout( new FlowLayout() ); mainList = new List( 10 ); // 10 rows mainList.setBackground( Color.WHITE ); newList = new List( 10 ); newList.setBackground( Color.WHITE ); listsPanel.add( mainList ); // ------------------------------------------------------ Button copyButton = new Button( "Copy >>" ); copyButton.addActionListener( new ActionListener () { // Listener is an inner class public void actionPerformed( ActionEvent e ) { // see supplemental notes on the web. int pos = mainList.getSelectedIndex(); // determining which entry has been selected if ( pos == -1 ) { System.err.println( "Select a song from the list" ); } else { newPlayList.addSong( model.getSongAt( pos ) ); // copy the Song displaySongs(); // refresh the view } } }); listsPanel.add( copyButton ); // ------------------------------------------------------ listsPanel.add( newList ); add( listsPanel, BorderLayout.CENTER ); // ------------------------------------------------------ // Creating a Panel to hold the buttons Panel controlPanel = new Panel(); // ------------------------------------------------------ Button sortByNameButton = new Button( "Sort By Name" ); sortByNameButton.addActionListener( new ActionListener () { public void actionPerformed( ActionEvent e ) { SortByName c = new SortByName(); // Comparator model.sort( c ); newPlayList.sort( c ); displaySongs(); } }); controlPanel.add( sortByNameButton ); // ------------------------------------------------------ Button sortByArtistButton = new Button( "Sort By Artist" ); sortByArtistButton.addActionListener( new ActionListener () { public void actionPerformed( ActionEvent e ) { SortByArtist c = new SortByArtist(); model.sort( c ); newPlayList.sort( c ); displaySongs(); } }); controlPanel.add( sortByArtistButton ); // ------------------------------------------------------ Button sortByAlbumButton = new Button( "Sort By Album" ); sortByAlbumButton.addActionListener( new ActionListener () { public void actionPerformed( ActionEvent e ) { SortByAlbum c = new SortByAlbum(); model.sort( c ); newPlayList.sort( c ); displaySongs(); } }); controlPanel.add( sortByAlbumButton ); // ------------------------------------------------------ Button printButton = new Button( "Print" ); printButton.addActionListener( new ActionListener () { public void actionPerformed( ActionEvent e ) { for ( int i=0; i