Q:

Button Listener adding and removing objects from a list

I'm trying to create a tab for an applet that can uses pet types from another tab.  This tab has the available pet types on the left, and the added pet types on the right.  A user can add a pet to the right column by electing it in the left column then clicking the add button, or remove a pet from the right column by selecting it and clicking on the remove button.  I can't figure out how to get the program to do this though, and keep getting errors.  Here is my code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class SelectPanel extends JPanel
 {
   private Vector petList, selectList;
   private Panel bPanel, nPanel;
   private JLabel sPets, aPets, nPets;
   private int numPets = 0;
   private JButton addPet, remove;
   private JList petsAvail, petTypes;
   private JScrollPane sPane, sPane2;

   public SelectPanel(Vector petList)
     {
      this.petList = petList;
  this.setLayout(new BorderLayout());

  bPanel = new Panel();
  nPanel = new Panel();
  nPanel.setLayout(new GridLayout(1,2));
  bPanel.setLayout(new GridLayout(2,1));

  petTypes = new JList(petList);
  petTypes.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  sPane = new JScrollPane(petTypes);

  selectList = new Vector();
  petsAvail = new JList(selectList);
  petsAvail.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  sPane2 = new JScrollPane(petsAvail);
  selectList.add(0, "Selected pet(s)");

  aPets = new JLabel("Available pet(s)");
  nPets = new JLabel("Selected pet(s)");
  nPets = new JLabel("The number of selected pets:" + numPets);
  addPet = new JButton("Add");
  remove = new JButton("Remove");

  add(petsAvail, BorderLayout.EAST);
  add(petTypes, BorderLayout.WEST);
  add(nPanel, BorderLayout.SOUTH);
  nPanel.add(nPets);
  add(bPanel, BorderLayout.CENTER);
  bPanel.add(addPet);
  bPanel.add(remove);

  addPet.addActionListener(new ButtonListener());
  remove.addActionListener(new ButtonListener());

 // orgranize components for the panel

 }

 public void updatePetList()
  {
        petTypes.updateUI();
        //This method can refresh the appearance of the list of pets
        //by calling updateUI() method for the JList.
        //It can be called from the CreatePanel class whenever a new pet type
        //is added to the vector and the JList appearence needs to be refreshed.
  }

 private class ButtonListener implements ActionListener
  {
       public void actionPerformed(ActionEvent event)
        {
            Object which = event.getSource();

        if(which == addPet){
            for (int p = 1; p < selectList.size(); p++){
                boolean check = false;
                String selectedPet =(String) petList.getSelectedValue();
                String petCheck =(String) selectList.get(p);
                if(selectedPet.equals(petCheck)){
                    check = true;
                    break;
                } else if(added == false){
                    petsAvail.add(selectedPet);
                    petsAvail.updateUI();
                    numPets++;
                }
            }
        } else if (which == remove){

            numPets--;
        }

        //When the added button is pushed, the selected pet
        //should be added to the right list and the number of
        //selected pets is incremented by 1.
        //When the remove button is pushed, the selected pet
        //should be removed from the right list and the number of
        //selected pets is decremented by 1.
        //
        //Be careful for the cases when no item has been selected.
    }
  } //end of ButtonListener class

} //end of SelectPanel class

Any assistance would be greatly appreciated.
The errors are:
C:\Users\[Redacted]\Desktop\Java\SelectPanel.java:83: error: cannot find symbol
                String selectedPet =(String) petList.getSelectedValue();
                                                    ^

 symbol:   method getSelectedValue()
  location: variable petList of type Vector
C:\Users\[Redacted]\Desktop\Java\SelectPanel.java:89: error: no suitable method found for add(String)
                        petsAvail.add(selectedPet);
                                 ^

method Container.add(Component,Object,int) is not applicable
      (actual and formal argument lists differ in length)
    method Container.add(Component,Object) is not applicable
      (actual and formal argument lists differ in length)
    method Container.add(Component,int) is not applicable
      (actual and formal argument lists differ in length)
    method Container.add(String,Component) is not applicable
      (actual and formal argument lists differ in length)
    method Container.add(Component) is not applicable
      (actual argument String cannot be converted to Component by method invocation conversion)
    method Component.add(PopupMenu) is not applicable
      (actual argument String cannot be converted to PopupMenu by method invocation conversion)
Note: C:\Users\[Redacted]\Desktop\Java\SelectPanel.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors

Tool completed with exit code 1

A:

You're trying to call methods that simply don't exist, and the compiler is rightly complaining. Your petlist is a Vector variable, and if you look at the Vector API you'll see what methods are available for this type.  The method getSelectedValue() is not one of them and really makes little sense for a Vector. 
Likewise Vector's don't have an add(...) method. Again, please get very familiar with the Java API as it will help prevent you from making these sorts of errors.

