当引用组件或变量错误时,JGRASP告诉我使用public或private

时间:2015-05-09 02:41:15

标签: java private public jgrasp

 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;

1 个答案:

答案 0 :(得分:0)

privatepublic在方法定义中是非法的(在这种情况下,是RoutinePanel的构造函数。)

您需要在任何方法定义之外的类中声明类成员变量。像:

private class RoutinePanel extends JPanel
{

  //labels
  private JLabel messageLabel;

  //constants for Routine Charges
  private final double OIL_CHANGE_CHARGE = 26.0;
  // ...

  public RoutinePanel()
  {