I'm having issues retrieving values from a "2d array" in Java. I know there isn't really such thing as a 2d array in Java, but bear with me. I am very new to Java, and am working on a project for my class. I'm supposed to be submitting information from a jTextField to an array, then pulling the information stored in the array back up for a summary report. Here's what I have so far:
public class KETTask1UI extends javax.swing.JFrame {
//Creates the "2d array" to store minutes worked and payment values
int[][] paymentArray = new int [20][2];
/**
* Creates new form KETTask1UI
*/
public KETTask1UI() {
initComponents();
}
private void runreportActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
for (int i=0; i<paymentArray.length; i++) {
for (int j=0; j<paymentArray[i].length; j++) {
//Blanks out the displayTextArea
displayTextArea.setText(" ");
//Displays the contents of the array in the displayTextArea
displayTextArea.append("History of minutes and payment entered:\n");
displayTextArea.append(String.valueOf(paymentArray[i][j]));
}
}
}
private void minutesActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void quitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
int min = Integer.parseInt(minutes.getText());
int pay = Integer.parseInt(payment.getText());
for (int i=0; i<paymentArray.length; i++) {
for (int j=0; j<paymentArray[i].length; j++) {
//Sets the amount of minutes worked and payment to the array
paymentArray[i][0] = min;
paymentArray[i][1] = pay;
//display a message to the user to let them know the values that they've entered.
displayTextArea.append("******************\nRaw Tutoring Earnings Data\n\nMinutes Earnings\n");
displayTextArea.append(String.valueOf(paymentArray[i][j]));
displayTextArea.append("\n\n******************");
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new KETTask1UI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextArea displayTextArea;
private javax.swing.JButton enterButton;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField minutes;
private javax.swing.JTextField payment;
private javax.swing.JLabel paymentLabel;
private javax.swing.JButton quit;
private javax.swing.JButton runreport;
private javax.swing.JLabel timeLabel;
// End of variables declaration
}
Now, currently when I click enter button, all it gives me is the following (30 being the last number of minutes and 20 being the last number for payment):
******************
Raw Tutoring Earnings Data
Minutes Earnings
30
************************************
Raw Tutoring Earnings Data
Minutes Earnings
20
This message repeats 20 times in the textArea. If I enter more data, it just does the same thing with the new numbers.
I need it to look like this:
******************
Raw Tutoring Earnings Data
Minutes Earnings
20 30
******************
When I enter new values and push the enter button again, I need it to display an updated list like this:
******************
Raw Tutoring Earnings Data
Minutes Earnings
20 30
30 15
******************