problem : After choosing "Select All" option other 4 option should be chosen too...(except Unselect All). I tried for 1 week but couldn't make it work. please help...

My Code :
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class Square extends MIDlet implements CommandListener, ItemStateListener {
private Display display;
private Form form;
private Command exitcommand;
private ChoiceGroup cg;
private int index1;
private int index2;

public Square() {
}

public void startApp(){
display = Display.getDisplay(this);
exitcommand = new Command("Exit", Command.EXIT, 1);
form = new Form("");
cg = new ChoiceGroup("Preferences", Choice.MULTIPLE);

cg.append("Cut", null);
cg.append("Copy", null);
cg.append("Paste", null);
cg.append("Delete", null);
index1= cg.append("Select All", null);
index2= cg.append("Unselect All", null);

form.append(cg);
form.addCommand(exitcommand);
cg.setItemCommandListener(null);
form.setCommandListener(this);

display.setCurrent(form);
}

public void pauseApp(){
}

public void destroyApp(boolean unconditional){
if(c== exitCommand){
destroyApp(false);
notifyDestroyed();
}

public void commandAction(Command c, Displayable s){
if (c == exitcommand){
destroyApp(false);
notifyDestroyed();
}
}

public void itemStateChanged(Item item){
int x= cg.getSelectedIndex();
//System.out.print(x);
if(x== index1){
for(int i=0; i<index1; i++){
cg.setSelectedIndex(i, true);
}
}

if(x== index2){
for(int i=0; i<index1; i++){
cg.setSelectedIndex(i, false);
}
}
}
}