プロジェクトのリスナーで「* Operator Undefined for JTextField、Double」というエラーが表示されます。これはJava GUIプロジェクトで、2つのテキストフィールドが必要です.1つは「時間」、もう1つは「レート」です。また、従業員のタイプと計算ボタンを列挙したコンボボックスが必要です。リスナーの下でスイッチのケース2(pay = hours * payRate;)にエラーが表示されます。 payRateで時間を掛けることができるように、テキストをどのように変換すればよいですか?JTextField、DoubleのJava *演算子が未定義
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);
}
}
}
'pay = hours * payRate' - ' hours'は 'JTextField'ですか、どのように倍で複数倍できますか? – MadProgrammer
'文字列strHours = Double.toString(時);'はまたsimularの理由のために問題を与えるつもりです – MadProgrammer
@MadProgrammer私たちはテキストフィールドを使用する必要があります、payrateは10進数を持つ必要がありますので私は信じられません整数を使用します。どのようなタイプを使用しますか? – lorac1969