我正在創建一個用於判斷體育賽事的GUI。有6個評委,他們分別輸入他們的分數到GUI中。然後他們點擊計算,該程序旨在將數字從低到高排序,然後從位置1到4取數字並給出平均值。Java swing - list.add問題
我已經編寫了通過控制檯輸入的代碼,並且工作,但是當我嘗試我的Gui時,'list.add'不起作用。我不知道我是否打算使用別的東西。
btnCalculate = new JButton("Calculate");
btnCalculate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
inGui = new Scanner (System.in);
double firstRun = getAverageOfRun(1);
double secondRun = getAverageOfRun(2);
double best;
if (firstRun > secondRun) {
best = firstRun;
} else {
best = secondRun;
}
textFieldRun1Score.setText(Double.toString(best));
}
private double getAverageOfRun (int runNumber) {
double total, avg;
int num1, num2, num3, num4, num5, num6;
List<Integer> list = new ArrayList<Integer>();
num1 = Integer.parseInt(textFieldRun1Score1.getText());
System.out.print(""+runNumber +": ");
list.add(textFieldRun1Score1.getText());
list.add(textFieldRun1Score2.getText());
list.add(textFieldRun1Score3.getText());
list.add(textFieldRun1Score4.getText());
list.add(textFieldRun1Score5.getText());
list.add(textFieldRun1Score6.getText());
Collections.sort(list);
total = list.get(1) + list.get(2) + list.get(3) + list.get(4);
avg = total/4;
textFieldBestScore.setText(Double.toString(avg));
return avg;
}
「不想工作「,它說什麼!顯示錯誤的詳細信息。 –
對不起,下次我會記住的。現在全部整理 – Nobby