I'm getting the error "* Operator Undefined for JTextField, Double" in the listener of a project. It's a Java GUI project, we're required to have two text fields, one for "hours" the other "rate". We are also required to have a combo box listing employee type and a calculation button. I'm getting the error in switch case 2 (pay = hours * payRate;) under the listener. How do I convert the text so I can multiply hours by payRate?
public class EmployeeControls extends JPanel
{
private JLabel cost, inputLabel1, inputLabel2, outputLabel, resultLabel;
private JTextField hours, rate;
private JComboBox employeeCombo;
private JButton calculateButton;
private double pay, bonus, payRate;
public EmployeeControls()
{
inputLabel1 = new JLabel("Hours:");
inputLabel2 = new JLabel("Rate:");
outputLabel = new JLabel("Pay:");
resultLabel = new JLabel("------");
hours = new JTextField(2);
rate = new JTextField(5);
hours.addActionListener(new CalcListener());
rate.addActionListener(new CalcListener());
String[] employeeTypes = {"Select an Employee
Type","Salaried","Hourly","Volunteer"};
employeeCombo = new JComboBox(employeeTypes);
calculateButton = new JButton("Calculate Pay");
cost = new JLabel("Pay: " + pay);
setPreferredSize(new Dimension (400, 100));
setBackground(Color.cyan);
add(employeeCombo);
add(calculateButton);
calculateButton.addActionListener(new CalcListener());
}
private class CalcListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
String text = rate.getText();
String strRate = Double.toString(payRate);
String text2 = hours.getText();
String strHours = Double.toString(hours);
int employeeType = employeeCombo.getSelectedIndex();
switch(employeeType)
{
case 0:
JOptionPane.showMessageDialog(null, "Select an Employee
Type");
break;
case 1:
pay = (2000.00 + bonus);
JOptionPane.showMessageDialog(null, "Enter bonus amount");
break;
case 2:
pay = hours * payRate;
break;
case 3:
pay = 0.00;
break;
}
cost.setText("Cost = " + pay);
}
}
}