JButton clearPlaylist = new JButton("Clear Playlist"); clearPlaylist.addActionListener(actionListener);
savePlaylistButton.setMnemonic('v'); JButton clearPlaylistButton = new JButton("Clear Playlist"); clearPlaylistButton.addActionListener(actionListener); clearPlaylistButton.setMnemonic('c');
	public JPanel createPanel()	{		// Create the JPanel		JPanel panel = new JPanel();		// Create the file chooser		fileChooser = new JFileChooser();		//songFileFilter = new SwingClientSongFileFilter();		//playlistFileFilter = new SwingClientPlaylistFileFilter();		//fileChooser.addChoosableFileFilter(songFileFilter);		//fileChooser.addChoosableFileFilter(playlistFileFilter);				// Create the action listener		SwingClientActionListener actionListener =			new SwingClientActionListener();		// Create the menus		menuBar = new JMenuBar();		frame.setJMenuBar(menuBar);		fileMenu = new JMenu("File");		fileMenu.setMnemonic(KeyEvent.VK_F);		fileMenu.getAccessibleContext().				setAccessibleDescription("File Menu");		menuBar.add(fileMenu);		preferencesMenuItem = new JMenuItem("Preferences", KeyEvent.VK_P);		preferencesMenuItem.getAccessibleContext().				setAccessibleDescription("Program preferences configuration");		preferencesMenuItem.addActionListener(actionListener);		fileMenu.add(preferencesMenuItem);		exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X);		exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4,			ActionEvent.ALT_MASK));		exitMenuItem.getAccessibleContext().				setAccessibleDescription("Exit Program");		exitMenuItem.addActionListener(actionListener);		fileMenu.add(exitMenuItem);		// Create the artist, album, song and song info labels		artistLabel = new JLabel("Artist:");		albumLabel = new JLabel("Album:");		songLabel = new JLabel("Song:");		songInfoLabel = new JLabel("");				// Create the song progress bar		songProgressBar = new JProgressBar();		songProgressBar.setString("00:00");		songProgressBar.setStringPainted(true);		JLabel initialSongTime = new JLabel("0:00");		currentSongLength = new JLabel("00:00");		// Create all of the buttons		JPanel topButtonPanel = new JPanel();		JButton previousSongButton = new JButton("Previous Song");		previousSongButton.addActionListener(actionListener);		JButton backButton = new JButton("Rewind");		backButton.addActionListener(actionListener);		playPauseButton = new JButton("Play");		playPauseButton.addActionListener(actionListener);		JButton stopButton = new JButton("Stop");		stopButton.addActionListener(actionListener);		JButton fastForwardButton = new JButton("Fast Forward");		fastForwardButton.addActionListener(actionListener);		JButton nextSongButton = new JButton("Next Song");		nextSongButton.addActionListener(actionListener);		JPanel bottomButtonPanel = new JPanel();		JButton addSongButton = new JButton("Add Song(s)");		addSongButton.addActionListener(actionListener);		JButton deleteSongButton = new JButton("Remove Song(s)");		deleteSongButton.addActionListener(actionListener);		JButton loadPlaylistButton = new JButton("Load Playlist");		loadPlaylistButton.addActionListener(actionListener);		JButton savePlaylistButton = new JButton("Save Playlist");		savePlaylistButton.addActionListener(actionListener);		JButton clearPlaylist = new JButton("Clear Playlist");		clearPlaylist.addActionListener(actionListener);		//JButton quitButton = new JButton("Quit");		//quitButton.addActionListener(actionListener);		// Create the checkboxes		itemListener = new SwingClientItemListener();		shuffleCheckBox = new JCheckBox("Shuffle", shuffleEnabled);		shuffleCheckBox.addItemListener(itemListener);		loopCheckBox = new JCheckBox("Loop Playlist", loopEnabled);		loopCheckBox.addItemListener(itemListener);		// Create all of the components of the playlist		playlistListModel = new DefaultListModel();		playlistList = new JList(playlistListModel);		playlistScrollPane = new JScrollPane(playlistList);		// Setup the layout manager		//panel.setLayout(new GridLayout(2,0));		GridBagLayout gridbag = new GridBagLayout();		GridBagConstraints c = new GridBagConstraints();		panel.setLayout(gridbag);		// Add the compenents to our panel		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 0;		c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(artistLabel, c);		panel.add(artistLabel);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 1;		c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(albumLabel, c);		panel.add(albumLabel);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 2;		c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(songLabel, c);		panel.add(songLabel);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 3;		c.gridheight = 1; c.gridwidth = 1;		c.fill = GridBagConstraints.NONE;		gridbag.setConstraints(initialSongTime, c);		panel.add(initialSongTime);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 3;		//c.gridheight = 1; c.gridwidth = GridBagConstraints.RELATIVE;		c.gridheight = 1; c.gridwidth = 3;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(songProgressBar, c);		panel.add(songProgressBar);		//c.gridx = 4; c.gridy = 3;		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 3;		c.gridheight = 1; c.gridwidth = 1;		c.fill = GridBagConstraints.NONE;		gridbag.setConstraints(currentSongLength, c);		panel.add(currentSongLength);		// Code to put in the top button row not in a panel		// See next section		//c.gridx = GridBagConstraints.RELATIVE; c.gridy = 4;		//c.gridheight = 1; c.gridwidth = 1;		//c.fill = GridBagConstraints.NONE;		//gridbag.setConstraints(previousSongButton, c);		//panel.add(previousSongButton);		//gridbag.setConstraints(backButton, c);		//panel.add(backButton);		//gridbag.setConstraints(playPauseButton, c);		//panel.add(playPauseButton);		//gridbag.setConstraints(stopButton, c);		//panel.add(stopButton);		//gridbag.setConstraints(fastForwardButton, c);		//panel.add(fastForwardButton);		//gridbag.setConstraints(nextSongButton, c);		//panel.add(nextSongButton);		// Put the top row of button in a seperate panel so that they		// can squish together		topButtonPanel.add(previousSongButton);		topButtonPanel.add(backButton);		topButtonPanel.add(playPauseButton);		topButtonPanel.add(stopButton);		topButtonPanel.add(fastForwardButton);		topButtonPanel.add(nextSongButton);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 4;		c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(topButtonPanel, c);		panel.add(topButtonPanel);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 5;		c.gridheight = 1; c.gridwidth = 1;		c.fill = GridBagConstraints.NONE;		gridbag.setConstraints(shuffleCheckBox, c);		panel.add(shuffleCheckBox);		gridbag.setConstraints(loopCheckBox, c);		panel.add(loopCheckBox);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 5;		c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.HORIZONTAL;		gridbag.setConstraints(songInfoLabel, c);		panel.add(songInfoLabel);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 6;		c.gridheight = 4; c.gridwidth = GridBagConstraints.REMAINDER;		c.fill = GridBagConstraints.BOTH;		gridbag.setConstraints(playlistScrollPane, c);		panel.add(playlistScrollPane);		c.gridx = GridBagConstraints.RELATIVE; c.gridy = 10;		c.gridheight = 1; c.gridwidth = 1;		c.fill = GridBagConstraints.NONE;		gridbag.setConstraints(addSongButton, c);		panel.add(addSongButton);		gridbag.setConstraints(deleteSongButton, c);		panel.add(deleteSongButton);		gridbag.setConstraints(loadPlaylistButton, c);		panel.add(loadPlaylistButton);		gridbag.setConstraints(savePlaylistButton, c);		panel.add(savePlaylistButton);		gridbag.setConstraints(clearPlaylist, c);		panel.add(clearPlaylist);		//gridbag.setConstraints(quitButton, c);		//panel.add(quitButton);		// Experiment in putting the buttom row of buttons in a panel		// Totally messed up the layout of the app		//bottomButtonPanel.add(addSongButton);		//bottomButtonPanel.add(deleteSongButton);		//bottomButtonPanel.add(loadPlaylistButton);		//bottomButtonPanel.add(savePlaylistButton);		//bottomButtonPanel.add(clearPlaylist);		//c.gridx = GridBagConstraints.RELATIVE; c.gridy = 10;		//c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER;		//c.fill = GridBagConstraints.HORIZONTAL;		//gridbag.setConstraints(bottomButtonPanel, c);		//panel.add(bottomButtonPanel);		// Create a timer to update the song info and progress bar		// every .5 seconds		timer = new javax.swing.Timer(500, new ActionListener() {			private int previousPlayState = PS_STOPPED;			private String previousSong = "";			public void actionPerformed(ActionEvent e) {				// Things that must be updated every time				songProgressBar.setValue(playedSeconds);				songProgressBar.setString(secToMinSec(playedSeconds));				if (loopEnabled != loopCheckBox.isSelected())				{					// Arrgh, setSelected generated an ItemListener event,					// which causes us to send the "new" state to the server,					// which sends it back, which....  So we disable the					// ItemListener while making the					System.err.println("loopEnabled: " + loopEnabled +						"  isSelected: " + loopCheckBox.isSelected());					loopCheckBox.removeItemListener(itemListener);					loopCheckBox.setSelected(loopEnabled);					loopCheckBox.addItemListener(itemListener);				}				// Things that only need to be updated if we're playing				// a new song or our playState changed.				if (playState != previousPlayState ||					currentSong != previousSong)				{					songProgressBar.setMaximum(totalSeconds);					currentSongLength.setText(secToMinSec(totalSeconds));					artistLabel.setText("Artist:  " + currentArtist);					albumLabel.setText("Album:  " + currentAlbum);					songLabel.setText("Song:  " + currentSong);					songInfoLabel.setText(currentSongInfo);					if (playState == PS_PLAYING)					{						playPauseButton.setText("Pause");					}					else if (playState == PS_PAUSED)					{						playPauseButton.setText("Unpause");					}					else					{						playPauseButton.setText("Play");					}					frame.pack();				}				previousPlayState = playState;				previousSong = currentSong;				if (playlistUpdated)				{					// See the comments above for the reasoning for the					// ItemListener twiddling.					System.err.println("Playlist updated");					shuffleCheckBox.removeItemListener(itemListener);					shuffleCheckBox.setSelected(shuffleEnabled);					shuffleCheckBox.addItemListener(itemListener);					refreshPlaylistList();					playlistUpdated = false;				}			}		});		timer.start();		return panel;	}