Hello. I'm having troubles with my JComboBox calculations. For example, if the strings in my JComboBox were String[] name = { "John", "Tom" }; And Tom was assigned 15% to his name. How can I have the cases in my action performed reach out to a calculation class to perform the calculation. What I want to do is have a total of the percent and amount added in a JTextfield to display in another JTextField. So basically the user is selecting a person, which has a certain percent assigned to the name depending on the person. Then the % is multiplied by a number from another textfield. The part I'm trying to figure out is how to display the total in another JTextfield depending on the person selected. If they pick case 0, it will only show John's amount in the totalField or if they pick Tom, it will only show Tom's amount in the totalField. What is the best way I can do this. I know how to do the calculations, it's the displaying part that I'm finding difficult. I left out alot of stuff, I'm just using this as an example. Thanks for hearing me out.
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == nameCombo)
{
switch(nameCombo.getSelectedIndex())
{
case 0:
break;
case 1:
break;
}
}
}
private void calc()
{
double dollarNumber = 00;
double totalNumber = 00;
dollarNumber = Double.parseDouble(dollarField.getText());
total = dollarNumber * johnPercent;
total = dollarNumber * tomPercent;
totalField.setText("$" + totalNumber);
damtDisplay.setText("" + total);
}