private class RoutinePanel extends JPanel
{
public RoutinePanel()
{
//labels
private JLabel messageLabel;
//constants for Routine Charges
private final double OIL_CHANGE_CHARGE = 26.0;
private final double LUBE_JOB_CHARGE = 18.0;
private final double RADIATOR_FLUSH_CHARGE = 30.0;
private final double TRANS_FLUSH_CHARGE = 80.0;
private final double INSPECTION_CHARGE = 15.0;
private final double MUFFLER_CHARGE = 100.0;
private final double TIRE_ROTATION_CHARGE = 20.0;
JGRASP告诉我在这种情况下使用私人是非法操作。但是,我的老师明确告诉我们以这种方式创建它。如果需要,我可以提供我们从教授那里收到的伪代码。
我也试过用公共替换私人。
对于包含私有的所有行,错误消息相同
JoesAutomotive.java:57:错误:非法开始表达
private JLabel messageLabel;
答案 0 :(得分:0)
private
和public
在方法定义中是非法的(在这种情况下,是RoutinePanel
的构造函数。)
您需要在任何方法定义之外的类中声明类成员变量。像:
private class RoutinePanel extends JPanel
{
//labels
private JLabel messageLabel;
//constants for Routine Charges
private final double OIL_CHANGE_CHARGE = 26.0;
// ...
public RoutinePanel()
{