基本上,我希望在单击“btnCalculate”按钮时更改“lblIndividualScore”的文本......但是当我单击它时,标签不会改变。我在它后面放了一个 println,我知道一切都被正确计算了……它不会改变。
下面是代码部分,有什么想法吗?
这是动作监听器片段
else if (e.getSource() == btnCalculate) {
setClassification();
setTargetOrLight();
setProneTotal();
setStandingTotal();
setKneelingTotal();
setIndividualTotal();
}
这是动作监听器调用的内容
public void setClassification() {
classification = (String)cmbClassification.getSelectedItem();
if (classification.equals("Senior") && target) {
txtProne2.setEditable(true);
txtKneeling2.setEditable(true);
txtStanding2.setEditable(true);
txtProne2.setVisible(true);
txtKneeling2.setVisible(true);
txtStanding2.setVisible(true);
lblStanding.setText("Standing");
lblKneeling.setText("Kneeling");
}
else if (classification.equals("Intermediate") || (classification.equals("Senior") && !target)) {
txtProne2.setEditable(false);
txtKneeling2.setEditable(false);
txtStanding2.setEditable(false);
txtProne2.setVisible(false);
txtKneeling2.setVisible(false);
txtStanding2.setVisible(false);
lblStanding.setText("Standing");
lblKneeling.setText("Kneeling");
}
else {
txtProne2.setEditable(false);
txtKneeling2.setEditable(false);
txtStanding2.setEditable(false);
txtProne2.setVisible(false);
txtKneeling2.setVisible(false);
txtStanding2.setVisible(false);
lblStanding.setText("Prone");
lblKneeling.setText("Prone");
}
}
public void setTargetOrLight() {
if (((String)cmbTarget.getSelectedItem()).equals("Target Rifle")) {
target = true;
}
else {
target = false;
}
}
public void setProneTotal() {
try {
if (classification.equals("Senior") && target) {
int prone1 = 0;
int prone2 = 0;
prone1 = Integer.parseInt(txtProne1.getText());
prone2 = Integer.parseInt(txtProne2.getText());
proneTotal = prone1 + prone2;
}
else if (classification.equals("Intermediate") || (classification.equals("Senior") && !target)) {
proneTotal = Integer.parseInt(txtProne1.getText());
}
else {
int prone1 = Integer.parseInt(txtProne1.getText());
int prone2 = Integer.parseInt(txtStanding1.getText());
int prone3 = Integer.parseInt(txtKneeling1.getText());
proneTotal = prone1 + prone2 + prone3;
}
}
catch(NumberFormatException nfe) {
System.err.println(nfe + ": You must enter a valid number - Prone");
}
}
public void setStandingTotal() {
try {
if (classification.equals("Senior") && target) {
int standing1 = 0;
int standing2 = 0;
standing1 = Integer.parseInt(txtStanding1.getText());
standing2 = Integer.parseInt(txtStanding2.getText());
standingTotal = standing1 + standing2;
}
else if (classification.equals("Intermediate") || (classification.equals("Senior") && !target)) {
standingTotal = Integer.parseInt(txtStanding1.getText());
}
else {
standingTotal = 0;
}
}
catch (NumberFormatException nfe) {
System.err.println(nfe + ": You must enter a valid number - Standing");
}
}
public void setKneelingTotal() {
try {
if (classification.equals("Senior") && target) {
int kneeling1 = 0;
int kneeling2 = 0;
kneeling1 = Integer.parseInt(txtKneeling1.getText());
kneeling2 = Integer.parseInt(txtKneeling2.getText());
kneelingTotal = kneeling1 + kneeling2;
}
else if (classification.equals("Intermediate") || (classification.equals("Senior") && !target)) {
kneelingTotal = Integer.parseInt(txtKneeling1.getText());
}
else {
kneelingTotal = 0;
}
}
catch (NumberFormatException nfe) {
System.err.println(nfe + ": You must enter a valid number - Kneeling");
}
}
public void setIndividualTotal() {
individualTotal = proneTotal + kneelingTotal + standingTotal;
lblIndividualTotal.setText("" + individualTotal);
System.err.println(individualTotal);
}
如上所述,我有那个结尾 println 'System.err.println(individualTotal);' 打印总数,它确实打印了,所以数字到了,但 lbl 没有改变。
如果您还有其他需要,请告诉我。
编辑:
setClassification() 方法中的 setTexts 也不起作用。