Hi everyone,
I got a small problem with my JList with MULTIPLE INTERVAL SELECTION.
When i click on a item it adds the price to the total and when i ctrl+click another item it again adds the price to the total
Then problem is when i deselect one of the selected items it adds the price to the total again.
Is there someway to subtract the selected items price from the total?.
Heres a snippet of code.
JListList tempList = new JList(list);
tempList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.tempList.addListSelectionListener(this);
public void valueChanged(ListSelectionEvent evt) {
int minIndex = tempList .getMinSelectionIndex();
int maxIndex = tempList .getMaxSelectionIndex();
for (int i = minIndex; i <= maxIndex; i++) {
if (evt.getValueIsAdjusting() == false & toppingList.isSelectedIndex(i)) {
double extra = 1.1;
double item = Double.parseDouble(itemprice.getText());
price = item + extra;
String res = Double.toString(price);
itemprice.setText(res);
}
Thanks.