Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default 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);
            
        }

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

  3. #3
    Join Date
    Jan 2011
    Posts
    2
    Rep Power
    0

    Default

    An whats does that mean ?

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    6

    Default

    Quote Originally Posted by raverz1tildawn View Post
    An whats does that mean ?
    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

  1. Replies: 0
    Last Post: 11-30-2010, 05:09 PM
  2. Populating the values in text fields
    By Inaam in forum Web Frameworks
    Replies: 2
    Last Post: 07-26-2010, 08:55 AM
  3. disapling text fields
    By javanew in forum AWT / Swing
    Replies: 2
    Last Post: 05-06-2010, 03:39 PM
  4. declaring fields without assigning values to them
    By diggitydoggz in forum New To Java
    Replies: 12
    Last Post: 01-03-2009, 08:22 PM
  5. Help with text fields in Java
    By romina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •