import java.awt.*; import java.awt.event.*; import javax.swing.*; // This is the Panel that contains represents the view of the // Music Store public class SongListPanel extends JPanel { // These are the components private JButton addButton; private JButton removeButton; private JList songList; // These are the get methods that are used to access the components public JButton getAddButton() { return addButton; } public JButton getRemoveButton() { return removeButton; } public JList getSongList() { return songList; } // This is the default constructor public SongListPanel(){ super(); // Use a GridBagLayout (lotsa fun) GridBagLayout layout = new GridBagLayout(); GridBagConstraints layoutConstraints = new GridBagConstraints(); setLayout(layout); // Add the buddy list songList = new JList(); songList.setPrototypeCellValue("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); JScrollPane scrollPane = new JScrollPane( songList, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); layoutConstraints.gridx = 0; layoutConstraints.gridy = 0; layoutConstraints.gridwidth = 3; layoutConstraints.gridheight = 5; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.insets = new Insets(10, 10, 10, 10); layoutConstraints.anchor = GridBagConstraints.NORTHWEST; layoutConstraints.weightx = 1.0; layoutConstraints.weighty = 1.0; layout.setConstraints(scrollPane, layoutConstraints); add(scrollPane); // Add the Add button addButton = new JButton("Add"); layoutConstraints.gridx = 3; layoutConstraints.gridy = 0; layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.insets = new Insets(10, 10, 10, 10); layoutConstraints.anchor = GridBagConstraints.EAST; layoutConstraints.weightx = 0.0; layoutConstraints.weighty = 0.0; layout.setConstraints(addButton, layoutConstraints); add(addButton); // Add the Remove button removeButton = new JButton("Remove"); layoutConstraints.gridx = 3; layoutConstraints.gridy = 1; layoutConstraints.gridwidth = 1; layoutConstraints.gridheight = 1; layoutConstraints.fill = GridBagConstraints.BOTH; layoutConstraints.insets = new Insets(10, 10, 10, 10); layoutConstraints.anchor = GridBagConstraints.EAST; layoutConstraints.weightx = 0.0; layoutConstraints.weighty = 0.0; layout.setConstraints(removeButton, layoutConstraints); add(removeButton); } }