我有一个数组(logic.res
),我存储了一些计算的结果,我想打印JTextarea (rez)
结果(该数组的一个元素)。我想在那个结果之前插入一个句子。选择哪个句子取决于该数组的哪个元素是结果(i
确定结果):
public void initComponents() {
calculate.addActionListener((ActionEvent p) -> {
try {
if (radioButton1.isSelected()) {
double condition1 = Double.parseDouble(txtCondition1.getText());
double condition2 = Double.parseDouble(txtConition2.getText());
double condition3 = Double.parseDouble(txtCondition3.getText());
double[] conditions = {condition1, condition2, condition3};
double shift1 = Double.parseDouble(txtShift1.getText());
double shift2 = Double.parseDouble(txtShift2.getText());
double shift3 = Double.parseDouble(txtShift3.getText());
double workingDays = 360;
YearWorkingHurs yearWorkingHours = new YearWorkingHurs(workingDays);
double[] shifts = {shift1, shift2, shift3};
double capacity1 = object.getCapacity();
double capacity2 = object2.getCapacity();
Logic logic = new Logic(capacity1, capacity2, conditions, shifts);
logic.solution();
long[] solution = logic.rez;
for (int i = 0; i < logic.rez.length; i++) {long[] solution = logic.res;
for (int i = 0; i < logic.res.length; i++) {
if (logic.res[i] >= 20000000 && logic.res[i] < 23000000) {
long temp = logic.res[i];
if (i == 0) {
rez.append("The choosen capacity has been fulfilled in good condition in one shift" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 1) {
rez.append("The choosen capacity has been fulfilled in good condition in 2 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 2) {
rez.append("The choosen capacity has been fulfilled in good condition in 3 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 3) {
rez.append("The choosen capacity has been fulfilled in semi-good condition in one shift" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 4) {
rez.append("The choosen capacity has been fulfilled in semi-good condition in 2 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 5) {
rez.append("The choosen capacity has been fulfilled in semi-good condition in 3 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 6) {
rez.append("The choosen capacity has been fulfilled in bad condition in one shift" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 7) {
rez.append("The choosen capacity has been fulfilled in bad condition in 2 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
draw.setEnabled(true);
} else if (i == 8) {
rez.append("The choosen capacity has been fulfilled in bad condition in 3 shifts" + "\n");
rez.append(String.valueOf(temp) + "\n");
}
} else {
}
}
}
}catch(Exception ex){
JOptionPane.showMessageDialog(rootPane,"Greska u proračunu,proverite unose");
}
obrisi.setEnabled(true);
});
但是使用这段代码我没有得到想要的句子,因为这既引用了我的数组中的元素数量,也引用了JTextArea
中的行数。
我希望在我的JTextArea
中获得的文本是,例如,数组的第8个元素中的结果,但因为它在第3行打印,所以它得到i==3
的句子1}}而不是i==8
。