得到了一个程序,它从 JTextFeld 获取用户输入并将它们添加到 JTextArea。这是动作监听器类:
/**
* Action listener class for reading in data and processing it
* when the Add reading button is clicked.
*/
class AddReadingListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
// Fetch the new reading details
int newDay = Integer.parseInt(dayEntryField.getText());
double newRain = Double.parseDouble(rainEntryField.getText());
// Clear the input
dayEntryField.setText("");
rainEntryField.setText("");
dataArea.append(newDay + ": " + newRain + " cm" + "\n");
}
}
}
我创建了一个数组来存储用户输入,但是我不知道如何将 JLabel 中的值存储到数组中?我假设它在按下按钮时需要在动作侦听器类中实现?
public void getRain()
{
double[] rArray = new double[32];
for(int c = 0;c<rArray.length;c++)
{
rArray[1] = Integer.parseInt(""+dayEntryField);
}
}
怀疑数组是否正确,但任何帮助将不胜感激!