error: class, interface, or enum expected when compiling
error: class, interface, or enum expected when compiling
public void buildButtonPanel()
{
buttonPanel = new JPanel();
calcButton = new JButton("Calculate Charges");
exitButton = new JButton("Exit");
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
total = routine.getRoutineCost() +
nonRoutine.getNonRoutineCost();
DecimalFormat dollar = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null, "Total: $" + dollar.format(total));
}
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
System.exit(0);
}
错误:class、界面或枚举预期
每一行都出现同样的错误。
我假设这是一个大括号错误,但我已经重做了 3 次大括号,但我在同一部分仍然遇到同样的错误。
buildButtonPanel 需要在 classes 之前有一个右括号。
它需要放在此处,因为您不能在方法中包含 classes。
buttonPanel.add(exitButton);
}
您向我们展示的所有代码都包含在 class 中吗? buildButtonPanel 是一种方法,必须在 class.
内
您的 actionPerformed 方法也没有大括号。
public void actionPerformed(ActionEvent e) {
// Your code goes here
}
public void buildButtonPanel()
{
buttonPanel = new JPanel();
calcButton = new JButton("Calculate Charges");
exitButton = new JButton("Exit");
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
total = routine.getRoutineCost() +
nonRoutine.getNonRoutineCost();
DecimalFormat dollar = new DecimalFormat("0.00");
JOptionPane.showMessageDialog(null, "Total: $" + dollar.format(total));
}
private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
System.exit(0);
}
错误:class、界面或枚举预期
每一行都出现同样的错误。
我假设这是一个大括号错误,但我已经重做了 3 次大括号,但我在同一部分仍然遇到同样的错误。
buildButtonPanel 需要在 classes 之前有一个右括号。
它需要放在此处,因为您不能在方法中包含 classes。
buttonPanel.add(exitButton);
}
您向我们展示的所有代码都包含在 class 中吗? buildButtonPanel 是一种方法,必须在 class.
内您的 actionPerformed 方法也没有大括号。
public void actionPerformed(ActionEvent e) {
// Your code goes here
}