GUI ButtonGroup


I'm having some issues setting up the actual list now. I'm trying to use ButtonGroup class but I'm getting missing symbol errors.
import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

    public class PetAdoptionGUI extends JPanel
   {
   
      JTextField costInput, descriptionInput;
      JButton inputButton;
      JTextArea dogOutput;
      JCheckBox specialNeeds;
      JRadioButton allButton;
      JRadioButton femaleButton;
      JRadioButton maleButton;
      JScrollPane scrollPane;
   
       public PetAdoptionGUI(ArrayList <Dog> dogs)
      {
         dogOutput = new JTextArea(7, 20);
         
         specialNeeds = new JCheckBox("Special Needs Only");
         JRadioButton allButton = new JRadioButton("All", true);
         JRadioButton femaleButton = new JRadioButton("Female Only", false);
         JRadioButton maleButton = new JRadioButton("Male Only", false);
      
         //all.setActionCommand();
         //all.setSelected(true);
      	
      	
         //femaleOnly.setActionCommand();
      	
      	
         //maleOnly.setActionCommand();
      	
      
      	
         
         
         Buttongroup group = new ButtonGroup();
         group.add(allButton);
         group.add(femaleButton);
         group.add(maleButton);
         
         JPanel radioPanel = new JPanel();
         radioPanel.setLayout(new gridLayout(3, 1));
         radioPanel.add(allButton);
         radioPanel.add(femaleButton);
         radioPanel.add(maleButton);
      	
         
      }
   }

Open in new window

Slck_PAsked:
Who is Participating?
 
robthewolfCommented:
This is really a whole different question from the one you originally posted.
Please try to post separate questions next time.

if you want this to work:
       public Dog(String Name, String Breed, String Gender, String SpecialNeeds, int Size, double Age )
      {
         this.Name = dogName;
         this.Breed = dogBreed;
         this.Gender = dogGender;
         this.SpecialNeeds = specialNeeds;
         this.Size = dogSize;
         this.Age = dogAge;
      }
you need to change it to
       public Dog(String Name, String Breed, String Gender, String SpecialNeeds, int Size, double Age )
      {
         this.dogName = Name;
         this.dogBreed = Breed;
         this.dogGender = Gender;
         this.specialNeeds = SpecialNeeds;
         this.dogSize = Size;
         this.dogAge = Age;
      }

this refers to instance fields.
also you had them on the wrong side of the =.  you set the variable on the left hand side of = from the value on the right had side.  This is a very serious mistake.  think about it like this in programming you say x = 1 + 1;  to set x to 2.  1 + 1 = x;  will not set work.  alternatively x = y sets x to the value of y.  y = x sets y to the value of x.  They are not equivalent.
     
   
 
0
 
robthewolfCommented:
You have made some typos.  I recommend using and IDE like eclipse or netbeans.  They show you your errors before you try to compile or run.  Can save a lot of time in debugging.
Check ButtonGroup you have also written Buttongroup in the same line.  make sure to use a G not a g
also with gridLayout it should be GridLayout.

This may just be a design point but it has caused you to make additional mistakes.
Some things you have declared as fields or instance variables (same thing) and others you have declared as local variables in the constructor.
I would declare all your components as fields in of the PetAdoptionGUI.  Then initialize them and set them up in the constructor.  What ever you do dont declare them in the constructor AND as fields.

for example you have JRadioButton allButton; as a field declaration
and JRadioButton allButton = new JRadioButton("All", true);
in the method.
the allButton that is the field will be null after the constructor has run as it is destroyed at the end.

You will also need to add radioPanel to something.

hope this gets you moving again.
0
 
Slck_PAuthor Commented:
Thanks a lot I've made the changes suggested but now I'm getting some missing symbol errors in my Dog class.  Any help with correcting these would be greatly appreciated.

   import java.awt.*;
   import java.awt.event.*;
   import javax.swing.*;

    public class PetAdoptionGUI extends JPanel
   {
   
      JTextArea dogOutput;
      JCheckBox specialNeeds;
      JRadioButton allButton;
      JRadioButton femaleButton;
      JRadioButton maleButton;
      JScrollPane scrollPane;
   
       public PetAdoptionGUI(ArrayList <Dog> dogs)
      {
         dogOutput = new JTextArea(7, 20);
         
         specialNeeds = new JCheckBox("Special Needs Only");
         allButton = new JRadioButton("All", true);
         femaleButton = new JRadioButton("Female Only", false);
         maleButton = new JRadioButton("Male Only", false);
     
         //all.setActionCommand();
         //all.setSelected(true);
            
            
         //femaleOnly.setActionCommand();
            
            
         //maleOnly.setActionCommand();
            
     
            
         
         
         ButtonGroup group = new ButtonGroup();
         group.add(allButton);
         group.add(femaleButton);
         group.add(maleButton);
         
         JPanel radioPanel = new JPanel();
         radioPanel.setLayout(new GridLayout(3, 1));
         radioPanel.add(allButton);
         radioPanel.add(femaleButton);
         radioPanel.add(maleButton);
            
         
      }
   }
import java.util.ArrayList;
    
    public class Dog implements Comparable <Dog>
   {
   // Instance variables
      private String name, breed,  specialNeeds;
      private char gender;
      private int size;
      private boolean specialNeedsInd;
      private double age;
      private static int MINATURE = 1;
      private static int SMALL = 2;
      private static int MEDIUM = 3;
      private static int LARGE = 4;
      private static int GIANT = 5;
      
            
       public Dog(String Name, String Breed, String Gender, String SpecialNeeds, int Size, double Age )
      {
         this.Name = name;
         this.Breed = breed;
         this.Gender = gender;
         this.SpecialNeeds = specialNeeds;
         this.Size = size;
         this.Age = age;
      }
      
   
   	
       public void setSize()//int Medium, int Minature, int Small, int Large, int Giant)
      {
         ArrayList arrayList = new ArrayList();
      
         arrayList.add(MINATURE);
         arrayList.add(SMALL);
         arrayList.add(MEDIUM);
         arrayList.add(LARGE);
         arrayList.add(GIANT);
      
      
         //MINATURE, SMALL, MEDIUM, LARGE, GIANT;
      }
         
       public int getSize()
      {      	
         return size;
         
      }
      
         
       public void setAge(double a)
      {
      }
   
       public double getAge()
      {
         return age;
      }
   	
   	   
       public String setName()
      {
      }
   
       public String getName()
      {
         return name;
      }
      
       public boolean setSpecialNeeds(String Blind, String Deaf, String Neurological, String Amputee)
      {
         if(specialNeedsInd == true)
         {
         //specialNeeds = Blind || Deaf || Neurological || Amputee;
         // }
         //else (specialNeeds == false)
         
         //specialNeeds = "";
         
         }
      }
   	
       public String getSpecialNeeds()
      {
      }
       public void setBreed()
      {
      
      }
      
       public String getBreed()
      {
         return breed;
      }
   
       public char getGender()
      {
         return gender;
      }
   
       public void setGender()
      {
      
      }
      
       public int compareTo(Dog d)
      {
         if(this.size < d.getSize())
         {
            return 1;
         }
         else if(this.size > d.getSize())
         {
            return -1;
         }
         else 
         {
            return 0;
         }
      }
      
       public String toString()
      {
         System.out.println("");
      }
   }

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Slck_PAuthor Commented:
(These errors occur for Name, Breed, Gender, SpecialNeeds, Size, and age.  I've initialized the variables so I'm confused why these errors are coming up.)
0
 
robthewolfCommented:
you have a line:
private String name, breed,  specialNeeds;

and then later:
     this.Name = name;
     this.Breed = breed;
     this.Gender = gender;
     this.SpecialNeeds = specialNeeds;
     this.Size = size;
     this.Age = age;

you have created the fields with out capital letters and then when you try to access them with this you use capital letters.  you must be consistent, programming languages are caps sensitive so name and Name are different.

Also later on you have methods that require a return value with out a return statement.  and curiously a method called setName without an input value and expecting a return value.  This makes no sense.

You really should use an IDE like eclipse or netbeans,  it makes these errors easy to spot and can be dealt with using the suggestions that the IDE will give you.  So you know you can compile working code.
0
 
Slck_PAuthor Commented:
I was trying to set the instance variables equal to the values in the constructor to instantiate the values.  I've changed the names and am now downloading netbeans but I'm still getting the error messages. Here's what I changed it to:
import java.util.ArrayList;
    
    public class Dog implements Comparable <Dog>
   {
   // Instance variables
      private String dogName, dogBreed,  specialNeeds;
      private char dogGender;
      private int dogSize;
      private boolean specialNeedsInd;
      private double dogAge;
      private static int MINATURE = 1;
      private static int SMALL = 2;
      private static int MEDIUM = 3;
      private static int LARGE = 4;
      private static int GIANT = 5;
      
            
       public Dog(String Name, String Breed, String Gender, String SpecialNeeds, int Size, double Age )
      {
         this.Name = dogName;
         this.Breed = dogBreed;
         this.Gender = dogGender;
         this.SpecialNeeds = specialNeeds;
         this.Size = dogSize;
         this.Age = dogAge;
      }
      
   
   	
       public void setSize()//int Medium, int Minature, int Small, int Large, int Giant)
      {
         ArrayList arrayList = new ArrayList();
      
         arrayList.add(MINATURE);
         arrayList.add(SMALL);
         arrayList.add(MEDIUM);
         arrayList.add(LARGE);
         arrayList.add(GIANT);
      
      
         //MINATURE, SMALL, MEDIUM, LARGE, GIANT;
      }
         
       public int getSize()
      {      	
         return size;
         
      }
      
         
       public void setAge(double a)
      {
      }
   
       public double getAge()
      {
         return age;
      }
   	
   	   
       public String setName()
      {
         ArrayList arrayName = new ArrayList();
         
         arrayName.add("Molly");
         arrayName.add("Frankie");
         arrayName.add("Bella");
         arrayName.add("Poppy");
         arrayName.add("Pretzel");
         arrayName.add("Jenna");
         arrayName.add("Bob");
         arrayName.add("Bear");
         arrayName.add("");
         arrayName.add("");
         arrayName.add("Mr. T");
         arrayName.add("Java");
         arrayName.add("Nelly");
         arrayName.add("Lucy");
         arrayName.add("Sandy");
      
      }
   
       public String getName()
      {
         return name;
      }
      
       public boolean setSpecialNeeds(String Blind, String Deaf, String Neurological, String Amputee)
      {
         if(specialNeedsInd == true)
         {
         //specialNeeds = Blind || Deaf || Neurological || Amputee;
         // }
         //else (specialNeeds == false)
         
         //specialNeeds = "";
         
         }
      }
   	
       public String getSpecialNeeds()
      {
      }
       public void setBreed()
      {
         ArrayList arrayBreed = new ArrayList();
         arrayBreed.add("German Shepherd");
         arrayBreed.add("Dachshund");
         arrayBreed.add("Dachshund");
      
      
      
      }
      
       public String getBreed()
      {
         return breed;
      }
   
       public char getGender()
      {
         return gender;
      }
   
       public void setGender()
      {
      
      }
      
       public int compareTo(Dog d)
      {
         if(this.size < d.getSize())
         {
            return 1;
         }
         else if(this.size > d.getSize())
         {
            return -1;
         }
         else 
         {
            return 0;
         }
      }
      
       public String toString()
      {
         System.out.println("");
      }
   }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.