Missing Symbol Errors

Getting missing symbols on methods I've called correctly.

Page 1 of 1

4 Replies - 941 Views - Last Post: 03 May 2010 - 10:37 AM Rate Topic: -----

#1 LiveFlow  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 75
  • Joined: 31-January 10

Missing Symbol Errors

Posted 03 May 2010 - 09:39 AM

I'm getting some errors that have me stuck on my code. I'm trying to call a method in my GUI from my driver but I'm getting missing symbol errors.. Here are the errors:
PetGUIDriver.java:16: cannot find symbol
symbol  : method getMenu()
location: class PetAdoptionGUI
         frame.setJMenuBar(guiPanel.getMenu());
                                   ^
PetAdoptionGUI.java:159: cannot find symbol
symbol  : class SelectionListener
location: class PetAdoptionGUI.ButtonListener.SelectedItemListener
               AnimalListDisplay.addJListSelectionListener(new SelectionListener());
                                                               ^
2 errors



Here's the GUI and the Driver:

   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import java.util.ArrayList;
   import javax.swing.JMenuBar;
    
    public class PetGUIDriver{
       public static void main(String args[]){       
         PetAdoptionGUI guiPanel = new PetAdoptionGUI();
         JFrame frame = new JFrame("Animal Adoption");
         frame.getContentPane().add(guiPanel);
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.pack();
         frame.setLocationRelativeTo(null);
         frame.setVisible(true);
         frame.setJMenuBar(guiPanel.getMenu());
      }
   }



   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;
   import java.util.ArrayList;
   import javax.swing.border.TitledBorder;
   import java.awt.List;
    
    public class PetAdoptionGUI extends JPanel{
   
      private AnimalListDisplay displayList;
      private JScrollPane scroller;
      private ArrayList<Animal> aList;
      
      private JButton ageButton, sizeButton;
      private JCheckBox specialNeeds, showDogs, showCats, showBirds;
   	
      private JPanel buttonPanel, checkPanel;
      private JMenuItem read, write;
      private JButton addAnimal;
      private InputPanel panel;
   	      
      private static final int LARGE_VERTICAL_SPACE = 60, SMALL_VERTICAL_SPACE = 20,
      X_DIMENSION = 600, Y_DIMENSION = 400;
   
       public PetAdoptionGUI(){ 
       
         populateList();
         displayList.setListData(aList.toArray());
       // instantiate GUI components
         scroller = new JScrollPane(displayList);
         
         panel = new InputPanel();
         buttonPanel = new JPanel();
         TitledBorder sortBorder = BorderFactory.createTitledBorder("Sort Options"); 
         buttonPanel.setBorder(sortBorder);
         sizeButton = new JButton("Size");
         ageButton = new JButton("Age");
         
         checkPanel = new JPanel();
         checkPanel.setLayout(new BoxLayout(checkPanel, BoxLayout.Y_AXIS));
         sortBorder = BorderFactory.createTitledBorder("Filter Options");
         checkPanel.setBorder(sortBorder);
         specialNeeds = new JCheckBox("Special needs only");
         showDogs = new JCheckBox("Show Dogs");
         showCats = new JCheckBox("Show Cats");
         showBirds = new JCheckBox("Show Birds");
         showDogs.setSelected(true);
         showCats.setSelected(true);
         showBirds.setSelected(true);
         
      	
      	
         this.setLayout(new BorderLayout());
         this.add(scroller, BorderLayout.CENTER);
         checkPanel.add(Box.createVerticalStrut(SMALL_VERTICAL_SPACE));
         checkPanel.add(specialNeeds);
         checkPanel.add(Box.createVerticalStrut(LARGE_VERTICAL_SPACE));
         checkPanel.add(showDogs);
         checkPanel.add(Box.createVerticalStrut(SMALL_VERTICAL_SPACE));
         checkPanel.add(showCats);
         checkPanel.add(Box.createVerticalStrut(SMALL_VERTICAL_SPACE));
         checkPanel.add(showBirds);
         this.add(checkPanel, BorderLayout.EAST);
         buttonPanel.add(sizeButton, BorderLayout.SOUTH);
         buttonPanel.add(ageButton, BorderLayout.SOUTH);
         this.add(buttonPanel, BorderLayout.SOUTH);
         this.add(panel, BorderLayout.WEST);
      
         this.setPreferredSize(new Dimension(X_DIMENSION,Y_DIMENSION));
         specialNeeds.addItemListener(new CheckBoxListener());
      	
         showBirds.addItemListener(new CheckBoxListener());
      	
         showDogs.addItemListener(new CheckBoxListener());
         
      	
         showCats.addItemListener(new CheckBoxListener());
         
         sizeButton.addActionListener(new ButtonListener());
         ageButton.addActionListener(new ButtonListener());
      }
      
   	
   	
   // public Bird(int aniID, int aniAge, int aniSize, Boolean aniNeeds, String animalDesc,String type)
       private void populateList(){
      
         ArrayList<Animal> list = new ArrayList<Animal>();
         list.add(new Bird(1001, 5, 7, true,"", "PARROT"));
         list.add(new Bird(1002, 3, 7, true, "", "Small Bird"));
      
         list.add(new Bird(1003, 2, 7, true,"", "Outdoor Bird"));
         list.add(new Bird(1004, 1, 7, false,"One Leg", "Outdoor Bird"));
         list.add(new Bird(1005, 1, 7, false,"One Eye", "Parrot"));
      
      
      	
         list.add(new Cat(1006, 2, 6, true, "", "Syphnx", "Mel", 11, "Indoor Only"));
         list.add(new Cat(1007, 1, 6, true, "", "Persian", "General", 12, "Indoor Only"));
         list.add(new Cat(1008, 3, 6, false, "", "Unknown", "Killer", 13, "Indoor Only"));
         list.add(new Cat(1009, 1, 6, false, "", "Unknown", "Oust", 14, "Outdoor/Indoor"));
         list.add(new Cat(1010, 1, 6, false, "", "Unknown", "Lysol", 15, "Outdoor/Indoor"));
      
               
         list.add(new Dog(1011, 1, 1, false, "", "Pitbull", "Sky", 17, false));
         list.add(new Dog(1012, 2, 2, false, "", "Pitbull", "Riley", 18, false));
         list.add(new Dog(1013, 3, 3, false, "", "Pitbull", "", 19, false));
         list.add(new Dog(1014, 4, 4, false, "", "Pitbull", "Washington", 20, false));
         list.add(new Dog(1015, 5, 5, false, "", "Pitbull", "Sprite", 21, false));
      
      
      // add them to an array list
         aList = list;
         displayList = new AnimalListDisplay(list);
      // send the arraylist to AnimalListDisplay
      }
      
       private class CheckBoxListener implements ItemListener
      {
      
          public void itemStateChanged(ItemEvent event)
         {
            if(event.getSource() == specialNeeds)
            {
               displayList.filterSpecialNeeds();
            }
            
            
            else if(event.getSource() == showDogs)
            {
               displayList.filterDogs();
            }
            
            else if(event.getSource() == showCats)
            {
               displayList.filterCats();  
            }
         }
      }
      
       private class ButtonListener implements ActionListener 
      {
          public void actionPerformed(ActionEvent eve)
         {
            if(eve.getSource() == sizeButton)
            {
               displayList.sortSize();
            }
            else if(eve.getSource() == ageButton)
            {
               displayList.sortAge();
            }
         }
      	
          private class SelectedItemListener implements ActionListener
         {
             public void actionPerformed(ActionEvent sel)
            {
               AnimalListDisplay.addJListSelectionListener(new SelectionListener());
            
            }
         }
          public JMenuBar getMenu(){
            JMenuBar menuBar = new JMenuBar();
            JMenu fileMenu = new JMenu("File");
            read = new JMenuItem("Read from file");
            write = new JMenuItem("Write from file");
            menuBar.add(fileMenu);
            fileMenu.add(read);
            fileMenu.add(write);
            return menuBar;
         
         }
      }
   
   }




Is This A Good Question/Topic? 0
  • +

Replies To: Missing Symbol Errors

#2 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Missing Symbol Errors

Posted 03 May 2010 - 09:57 AM

you don't have the SelectionListener class in your code. perhaps you meant the interface ListSelectionListener? or you intend to write that class yourself?

also, as for getMenu method, check your curly braces, You may misplaced the curly braces, so the getMenu class is inside the ButtonListener class.
also, SelectedItemListener is inside the ButtonListener class.
Was This Post Helpful? 0
  • +
  • -

#3 LiveFlow  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 75
  • Joined: 31-January 10

Re: Missing Symbol Errors

Posted 03 May 2010 - 10:01 AM

@ Japanir: Yes you're right I meant the interface. I'm trying to write it as such but I'm still getting the symbol error.
               AnimalListDisplay.addJListSelectionListener(new ListSelectionListener());



The curlybraces suggestion fixed the getMenu method though thanks a lot.
Was This Post Helpful? 0
  • +
  • -

#4 japanir  Icon User is offline

  • jaVanir
  • member icon

Reputation: 1010
  • View blog
  • Posts: 3,025
  • Joined: 20-August 09

Re: Missing Symbol Errors

Posted 03 May 2010 - 10:09 AM

You may want to take a look at this tutorial:
How to write a ListSelectionListener
http://java.sun.com/...onlistener.html
Was This Post Helpful? 0
  • +
  • -

#5 LiveFlow  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 75
  • Joined: 31-January 10

Re: Missing Symbol Errors

Posted 03 May 2010 - 10:37 AM

I've looked through the tutorial and I have just one more question.. If I'm just trying to get the selected item to show in a dialog box would I need to write out the information again in the list selection listenener? Ex:

     private class SelectedItemHandler implements ListSelectionListener
         {
             public void valueChanged (ListSelectionEvent sel)
            {
               AnimalListDisplay.addJListSelectionListener(new ListSelectionListener());
            
               ListSelectionModel l = (ListSelectionModel)e.getSource();

int selectedItem =  e.getSelectedItem();
output.append("ID:" + ID + "Name" + name + etc..);

            
            }
         }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1