In my java code I get this error. Enyone fix it for me Plz?

cannot find symbol :method getSelectedItem()

This is my code.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;


public class soda extends Applet implements ActionListener, ItemListener {
Label lblhead,lblfoot,lblsize,lbltype,lblamt,lblbal,lblavilability;
Button b1,b2,b3,b4,b5,b6,b7,btnref;
Choice choice1;
Checkbox ch1,ch2,ch3,ch4,ch5;
float num,money,change;
CheckboxGroup cbg,cbg1;
TextField txtamt1,txtbal,txtfoot,txtavilability;


float itemprice=20;


public int cola_10oz_reg =3;
public int cola_10oz_die =3;
public int cola_16oz_reg =3;
public int cola_16oz_die =3;
public int org_10oz_reg =3;
public int org_16oz_reg =3;
public int org_10oz_die =3;
public int org_16oz_die =3;
public int lim_10oz_reg =3;
public int lim_16oz_reg =3;


public void init() {


lblhead = new Label();


cbg = new CheckboxGroup();
ch1 = new Checkbox("COLA", cbg, false);
ch2 = new Checkbox("ORANGE", cbg, false);
ch3 = new Checkbox("LIME", cbg, false);


b1 = new Button();
b2 = new Button();
b3 = new Button();
b4 = new Button();
b5 = new Button();
b6 = new Button();
b7 = new Button();


choice1 = new Choice();



lblsize = new Label();
lbltype = new Label();


cbg1 = new CheckboxGroup();
ch4 = new  Checkbox("Regular", cbg, true);
ch5 = new Checkbox("Diet", cbg, false);


lblamt = new Label();
txtamt1 = new TextField();
lblbal = new Label();
txtbal = new TextField();
btnref = new Button();
txtfoot = new TextField();
lblavilability = new Label();
txtavilability = new TextField();


setBackground(new Color(255, 153, 153));
setLayout(null);


lblhead.setAlignment(Label.CENTER);
lblhead.setFont(new Font("Calibri", 1, 18));
lblhead.setText("Soda Vending Machine");
add(lblhead);
lblhead.setBounds(80, 30, 230, 30);



add(ch1);
ch1.setBounds(60, 70, 58, 20);



add(ch2);
ch2.setBounds(60, 100, 77, 20);



add(ch3);
ch3.setBounds(60, 130, 53, 20);


b1.setBackground(new Color(0, 153, 153));
b1.setLabel("RM 00.10");
add(b1);
b1.setBounds(320, 60, 70, 24);


b2.setBackground(new Color(0, 153, 153));
b2.setLabel("RM 00.20");
add(b2);
b2.setBounds(320, 100, 68, 24);


b3.setBackground(new Color(0, 153, 153));
b3.setLabel("RM 00.50");
add(b3);
b3.setBounds(320, 140, 68, 24);


b4.setBackground(new Color(0, 153, 153));
b4.setLabel("RM 1.00");
add(b4);
b4.setBounds(320, 180, 70, 24);


b5.setBackground(new Color(0, 153, 153));
b5.setLabel("RM 2.00");
add(b5);
b5.setBounds(320, 220, 70, 24);


b6.setBackground(new Color(0, 153, 153));
b6.setLabel("RM 5.00");
add(b6);
b6.setBounds(320, 260, 70, 24);


b7.setBackground(new Color(0, 153, 153));
b7.setLabel("RM 10.00");
add(b7);
b7.setBounds(320, 300, 70, 24);


choice1.add("10 oz");
choice1.add("16 oz");
add(choice1);
choice1.setBounds(200, 170, 90, 20);


lblsize.setText("SIze");
add(lblsize);
lblsize.setBounds(60, 170, 70, 20);


lbltype.setText("Type");
add(lbltype);
lbltype.setBounds(60, 200, 30, 20);


//ch4.setLabel("Regular");
add(ch4);
ch4.setBounds(200, 200, 84, 20);


//ch5.setLabel("Diet");
add(ch5);
ch5.setBounds(200, 230, 48, 20);


lblamt.setText("Total Amount");
add(lblamt);
lblamt.setBounds(60, 270, 76, 20);
add(txtamt1);
txtamt1.setBounds(200, 270, 90, 20);


//btnbal.setBackground(new Color(0, 153, 153));
lblbal.setText("Balance");
add(lblbal);
lblbal.setBounds(60, 300, 61, 24);
add(txtbal);
txtbal.setBounds(200, 300, 90, 20);


lblavilability.setBackground(new Color(255, 153, 153));
lblavilability.setText("Availability");
add(lblavilability);
lblavilability.setBounds(60, 323, 60, 20);
add(txtavilability);
txtavilability.setBounds(200, 323, 90, 20);


btnref.setBackground(new Color(0, 153, 153));
btnref.setLabel("Take Soda and Refresh");
add(btnref);
btnref.setBounds(60, 350, 320, 24);


add(txtfoot);
txtfoot.setBounds(200, 300, 90, 20);



ch1.addItemListener(this);
ch2.addItemListener(this);
ch3.addItemListener(this);
ch4.addItemListener(this);
ch5.addItemListener(this);


b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
btnref.addActionListener(this);
}
public void itemStateChanged(ItemEvent ie) {


if(ie.getItemSelectable()==ch1)
{
setBackground(Color.red);
ch5.setVisible(true);
}
if(ie.getItemSelectable()==ch2)
{
setBackground(Color.orange);
ch5.setVisible(true);
}
if(ie.getItemSelectable()==ch3)
{
setBackground(Color.green);
ch5.setVisible(false);
}


if(choice1.getSelectedItem()=="10 oz"){
itemprice=(float)1.6;
repaint();
}


}


public void actionPerformed(ActionEvent e) {



if(e.getSource()==b1){


money+=0.10;
repaint();
}



if(e.getSource()==b2){


money+=0.2;
repaint();
}



if(e.getSource()==b3)


money+=0.50;
repaint();


if(e.getSource()==b4){


money+=1;
repaint();
}



if(e.getSource()==b5){


money+=2;
repaint();
}



if(e.getSource()==b6)
{


money+=5;
repaint();
}



if(e.getSource()==b7){


money+=10;
repaint();
}


if(e.getSource()==btnref){
money=0;if (cbg.getSelectedCheckbox()==ch1 && choice1.getSelectedItem()=="10 oz" && ch4.getSelectedItem()=="REGULAR"){
if(cola_10oz_reg<=0){
txtavilability.setText("Not available");
}
}


txtamt1.setText("");
txtbal.setText("");
txtfoot.setText("Thank U & come again");
}


}


public void paint(Graphics g){
num=num+money;
txtamt1.setText(Float.toString(money));
//change=num-itemprice;
txtbal.setText(Float.toString(money-itemprice));
}


}

Edited 3 Years Ago by happygeek: fixed formatting

Do you see a getSelectedItem() in the Checkbox API? Would such a method even make sense for a checkbox?

Note, please place all code in [code] [/code] tags when you post and give your threads a more descriptive title than "Help!" (as you seem to title all of your posts).

ok,
1: use code tags
2: Forum Rules keep it organized don't use names like "HELP!!"
3:don't use "==" for string comparison use .equals(String) or .equalsIgnoreCase(String) , as "==" won't work correctly
4:ch4 is a checkbox and doesn't have a get selected item method it has an isSelected method that is a boolean

EDIT: was writing this post as Ezzaral replied, sorry for repeating

This article has been dead for over six months. Start a new discussion instead.