Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By Tolls

Thread: Cannot find isSelected() method for JCheckBox

  1. #1
    coderz is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Cannot find isSelected() method for JCheckBox

    Hello Everyone,

    I am in desperate need of help. I have a gui program with checkboxes and when I use isSelected() method to see which box is selected, I am getting the error stating "cannot find symbol: method isSelected()".

    Please help me.
    Java Code:
    package bhasinprogram2;
    
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.Component;
    import java.awt.GridLayout;
    
    import java.text.*;
    import javax.swing.*;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /**
     *
     * @author Robogeekster
     */
    public class Pizza extends JFrame implements ActionListener,KeyListener{
        
        
        double smallPizzaPrice = 6.50, mediumPizzaPrice = 8.50,largePizzaPrice = 10.0;
        public static String[]PizzaSize;// ;
        private String[] CrustType;//{"Thin","Medium","Pan"};
        private String[] PizzaToppings;//{"Tomato","Green Pepper","Black Olives","Mushroom","Extra Cheese","Pepproni","Sausage"};
        
        static final String CLEAR = "clear";
        static final String TOTAL = "total";
        private Object button1;
        private Object small;
        private Object text1;
        private Object Small;
        private Object medium;
        private Object large;
        private Object checkbox1;
        private Object checkbox2;
        private Object checkbox3;
        private Object checkbox4;
        private Object checkBox5;
        private Object checkBox7;
        private Object checkBox6;
        
     
        
        Pizza()
        {
            getContentPane().setLayout(null);
            setBackground(Color.white);
            
            
          //  PizzaSize = new String[3];
           // CrustType = new String[3];
           // PizzaToppings = new String[7];
            initializeComponents();
        }
        
        
     public final void initializeComponents()
     {
         
         JLabel label1 = new JLabel("Name: ");
         JLabel label2 = new JLabel("Address: ");
         
         JLabel SizeLabel = new JLabel("Select Pizza size");
         SizeLabel.setFont(new Font("Arial",Font.BOLD,14));
         
         JLabel Toppings = new JLabel("Each Topping $1.50");
         Toppings .setForeground(new Color(0,0,205));
         Toppings.setFont(new Font("Arial",Font.BOLD,14));
         
         JLabel CrustLabel = new JLabel("Pizza Type");
         CrustLabel.setForeground(new Color(200,0,0));
         CrustLabel.setFont(new Font("Arial",Font.BOLD,14));
         
         JTextField text1 = new JTextField(20);
         JTextField text2 = new JTextField(20);
         
         JRadioButton Small = new JRadioButton("Small: $6.50",true);
         JRadioButton medium = new JRadioButton("Medium: $8.50",true);
         JRadioButton large = new JRadioButton("Large: $10.00",true);
         ButtonGroup group1 = new ButtonGroup();
         group1.add(Small);
         group1.add(medium);
         group1.add(large);
         
         JCheckBox checkbox1 = new JCheckBox("Tomato",false);
         JCheckBox checkbox2 = new JCheckBox("Green Pepper",false);
         JCheckBox checkbox3 = new JCheckBox("Black Olives",false);
         JCheckBox checkbox4 = new JCheckBox("Mushrooms",false);
         JCheckBox checkBox5 = new JCheckBox("Extra Cheese",false);
         JCheckBox checkBox6 = new JCheckBox("Pepproni",false);
         JCheckBox checkBox7 = new JCheckBox("Sausage",false);
         
         JButton button1 = new JButton("Process Order");
         Small.addActionListener(this);
         medium.addActionListener(this);
         large.addActionListener(this);
         
         checkbox1.addActionListener(this);
         checkbox2.addActionListener(this);
         checkbox3.addActionListener(this);
         checkbox4.addActionListener(this);
         checkBox5.addActionListener(this);
         checkBox6.addActionListener(this);
         checkBox7.addActionListener(this);
         
         button1.addActionListener(this);
         
         label1.setBounds(50,50,200,20);
         label2.setBounds(50,80,200,20);
         
         text1.setBounds(200,50,200,20);
         text2.setBounds(200,80,200,20);
         
         Small.setBounds(300,170,100,20);
         medium.setBounds(400,170,100,20);
         large.setBounds(500,170,100,20);
         
         checkbox1.setBounds(50,230,300,20);
         checkbox2.setBounds(50,260,300,20);
         checkbox3.setBounds(50,290,300,20);
         checkbox4.setBounds(50,320,300,20);
         checkBox5.setBounds(50,350,300,20);
         checkBox6.setBounds(50,380,300,20);
         checkBox7.setBounds(50,410,300,20);
         
         button1.setBounds(50,600,100,20);
         
         add(label1);
         add(label2);
         
         add(text1);
         add(text2);
         
         add(small);
         add(medium);
         add(large);
         
         add(checkbox1);
         add(checkbox2);
         add(checkbox3);
         add(checkbox4);
         add(checkBox5);
         add(checkBox6);
         add(checkBox7);
         
         setVisible(true);
          setSize(1000,700);
     }
     
        @Override
     public void actionPerformed(ActionEvent e)
     {
         if(e.getSource()== button1)
         {
             JOptionPane.showMessageDialog(this,text1.toString()+",Thank you"
                                            +"\nYour pizza will be ready in few minutes",
                                             "Order Confirmed",JOptionPane.INFORMATION_MESSAGE);
         }
         
         CalculatePrice();
     }
     
     private void CalculatePrice()
     {
         double cost = 0.0;
         
         NumberFormat numberForm= NumberFormat.getNumberInstance();
         DecimalFormat moneyForm = (DecimalFormat)numberForm;
         moneyForm.applyPattern("0.00");
         
         if(Small.isSelected())
         {
             cost += smallPizzaPrice;
         }
         
         if(medium.isSelected())
         {
             cost += mediumPizzaPrice;
         }
         
         if(large.isSelected())
         {
             cost += largePizzaPrice;
         }
         
         if(checkbox1.isSelected())
         {
             cost += 1.50;
         }
         if(checkbox2.isSelected())
         {
             cost += 1.50;
         }
         if(checkbox3.isSelected())
         {
             cost += 1.50;
         }
         if(checkbox4.isSelected())
         {
             cost += 1.50;
         }
         if(checkBox5.isSelected())
         {
             cost += 1.50;
         }
         if(checkBox6.isSelected())
         {
             cost += 1.50;
         }
         if(checkBox7.isSelected())
         {
             cost +=1.50;
         }
             
     }
    
     public void KeyTyped(KeyEvent e)
     {
     }
     
     public void KeyPressed(KeyEvent e)
     {
         
     }
     
     public void KeyReleased(KeyEvent e)
     {
         
     }
    
        @Override
        public void keyTyped(KeyEvent ke) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        @Override
        public void keyPressed(KeyEvent ke) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
    
        @Override
        public void keyReleased(KeyEvent ke) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
     
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Cannot find isSelected() method for JCheckBox

    That's because, as far as the compiler is concerned, those are not JCheckBoxes.
    You have declared them as Objects.

    Is there any particular reason for that?
    Fubarable likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Can not find subclass method
    By samanesh in forum New To Java
    Replies: 4
    Last Post: 11-24-2011, 05:26 PM
  2. HELP! can't find symbol-method
    By Jack9333 in forum New To Java
    Replies: 2
    Last Post: 03-04-2011, 01:48 AM
  3. Can't find method
    By 01allenh in forum New To Java
    Replies: 1
    Last Post: 03-25-2009, 07:46 PM
  4. Can't find out how to get this method working :)
    By Shadaw in forum Java Applets
    Replies: 2
    Last Post: 12-29-2008, 05:35 PM
  5. Problems with Find method in EJB
    By Nick15 in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 05-14-2007, 01:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •