Results 1 to 4 of 4
- 01-07-2011, 10:07 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Java 2D array get values from text fields
I have to write a GUI that contains 2 textfields and 2 buttons. When the first button "Enter" is clicked it submits the values in the 2 textfields and stores them in a 2D array. When the second button "Report" is clicked is outputs all of the values in the array to a textarea. I'm having an issue populating the array where whenever i click the eneter button it doesn't store the values. Below is what I have so far. Any help would be greatly appreciated.
Java Code:package TutoringSessionPackage; import javax.swing.*; public class TutoringSessionUI extends javax.swing.JFrame { double [][] tutorArray = new double[20][2]; private void EnterButtonActionPerformed(java.awt.event.ActionEvent evt) { for(int i = 0; i < tutorArray.length; i++){ for(int j = 0; j < tutorArray[i].length; j++){ System.out.println(i); System.out.println(j); //double minutesInt = 0; //double moneyInt = 0; double minutesInt = Double.parseDouble(TimeText.getText()); double moneyInt= Double.parseDouble(MoneyText.getText()); //Checks for negative numbers in Minutes and throws exception if found. if (minutesInt < 0) { IllegalArgumentException exception = new IllegalArgumentException("Invalid payment amount."); throw exception; } //Checks for negative numbers in Money and throws exception if found. if (moneyInt < 0) { IllegalArgumentException exception = new IllegalArgumentException("Invalid time amount."); throw exception; } tutorArray[j][0] = minutesInt; tutorArray[j][1] = moneyInt; //System.out.println(tutorArray[j][0]); //System.out.println(tutorArray[j][1]); //System.out.println(); TimeText.setText(""); MoneyText.setText(""); } } } private void QuitButtonActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: System.exit(0); } private void ReportButtonActionPerformed(java.awt.event.ActionEvent evt) { String tutorOutPut = Double.toString(tutorArray[0][0]); String tutorOutput2 = Double.toString(tutorArray[0][1]); ReportArea.append(tutorOutPut + " " + tutorOutput2); }
- 01-07-2011, 11:38 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
- 01-08-2011, 12:30 AM #3
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
An whats does that mean ?
- 01-08-2011, 12:56 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
It means the same question was asked elsewhere. Linking between the forums helps both the original poster and the contributors in that everyone is on the same page, people know what has been tried and/or asked, know the current state of the problem, and more importantly know if the question has been answered (quite often solutions are given elsewhere and contributors end up spending time - time they could be helping someone else - answering a question which has already been answered)
Similar Threads
-
Retaining values entered by users in the installer fields when they come back to that
By salman.kagzi in forum New To JavaReplies: 0Last Post: 11-30-2010, 05:09 PM -
Populating the values in text fields
By Inaam in forum Web FrameworksReplies: 2Last Post: 07-26-2010, 08:55 AM -
disapling text fields
By javanew in forum AWT / SwingReplies: 2Last Post: 05-06-2010, 03:39 PM -
declaring fields without assigning values to them
By diggitydoggz in forum New To JavaReplies: 12Last Post: 01-03-2009, 08:22 PM -
Help with text fields in Java
By romina in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:29 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks