一旦添加到JPanel,为什么不应该更改JProgressBar?

时间:2018-06-12 17:01:29

标签: java swing jpanel components jprogressbar

直接和简单: 想象一下,我们在一个扩展JPanel的类

  -- Nutrition
  INSERT INTO #ChronicCondition(IdApplicant, ExamDate, Condition, TreatmentNeeded, TreatmentReceived, Status, Comment)
    SELECT  #Enroll.IdApplicant,
            HltNutrition.ExamDate,
            'Nutrition',
            HltNutrition.TrtNeed,
            HltNutrition.TrtStatus,
            HltNutrition.Status,
            SUBSTRING (HltNutrition.Comment, 1, 1000)
    FROM    #Enroll
            JOIN HltNutrition ON HltNutrition.IdApplicant = #Enroll.IdApplicant
    WHERE   HltNutrition.Overweight = 1  

  -- Chronic
  INSERT INTO #ChronicCondition(IdApplicant, ExamDate, Condition, TreatmentNeeded, TreatmentReceived, Status, Comment)
    SELECT  #Enroll.IdApplicant,
            HltChronic.ExamDate,
            CASE ChronicCondition.Id
              WHEN 3 THEN 'Other' + ISNULL(' - ' + hltChronic.ConditionOther, '')
              ELSE ChronicCondition.Condition
            END,
            HltChronic.TrtNeed,
            HltChronic.TrtStatus,
            hltChronic.Status,
            SUBSTRING (HltChronic.Comment, 1, 1000)
    FROM    #Enroll 
            JOIN hltChronic ON hltChronic.idApplicant = #Enroll.idApplicant
            JOIN ChronicCondition ON ChronicCondition.Id = hltChronic.Condition

为什么?

不,我无法在任何地方找到它。我在广泛搜索这个具体问题。

1 个答案:

答案 0 :(得分:0)

Java变量的作用(实际上)就像指针一样。

您创建了df.schema并将其添加到JProgressBar - 并在变量JPanel中将指针存储到此处。当您致电bar时,您会更改指针指向的内容,但会更改原始bar = new JProgressBar(0, 0, 10);(已添加到JProgressBar的内容),您现在有一个,不同的JPanel已添加到您的JProgressBar),因此在其上设置值不会修改 JPanel上可见

的那个。

这与以下原因相同:

JPanel

将打印String name = "Billy"; String otherName = name; name = "Jimmy"; System.out.println(otherName);