1 year ago
#165201
K_Cole369
Add the value from multiple selected items in a Multi Selection JList to another variable
I am newish to Java and I am working on a program where the user can select items to add to their skateboard design. There are 4 jLists with different items they can select. The first 3 jList the user can only select one item. They can then choose multiple items from the forth list. The user will then click the Calculate button to get the subtotal, sales tax, and final total. My question is: how do I get the subtotal to include all items selected are added the the subtotal. As I have it now only the first item is added.
double l = jList4.getSelectedIndex();
if(l == 0){
sbtotal = sbtotal + 10;
}
if(l == 1){
sbtotal = sbtotal + 30;
}
if(l ==2){
sbtotal = sbtotal + 2;
}
if(l ==3){
sbtotal = sbtotal + 3;
}
if(l ==0 && l == 1){
sbtotal = sbtotal + 40;
}
I have added a photo of the JFrame to show how only the first selected item is being added to the subtotal and not the second item. Any help would be appreciated.
java
swing
jlist
multipleselection
0 Answers
Your Answer