Results 1 to 5 of 5
  1. #1
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default Problem returning Array values Please help

    I am trying to return my array values but cant seem to get them to display. Can someone please point me in the right direction.





    Java Code:
    private void EnterActionPerformed(java.awt.event.ActionEvent evt) {
            // Enter Button functionality
            Scanner input = new Scanner(System.in);
            try{
               //convert text input to integer for array
                    int timeInt = Integer.parseInt(timeField.getText());
               //input array values in a loop
                   for (index = 0; index > 0; index++)
                    {
                        tarray[index][0] = input.nextInt(timeInt);
                    }
                    index++;
            }
            catch (Exception e) {
               JOptionPane.showMessageDialog(this, "Invalid Input in the Time field","ERROR",JOptionPane.ERROR_MESSAGE);
             return;
            }
            try{
                //convert text input to integer for array
                    int moneyInt = Integer.parseInt(moneyField.getText());
               //input array values in a loop
                   for (index = 0; index > 0; index++)
                    {
                        tarray[index][1] = input.nextInt(moneyInt);
                    }
                    index++;
               //resets the text fields for new values
                  //  moneyField.setText("");
                   // timeField.setText("");
                    [COLOR="Red"]reportArea.append("money is at" + " " + tarray[index][1]);
                    reportArea.append(" " + "time is at" + " " + tarray[index][0]);[/COLOR]        }
            catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Invalid Input in the Money field","ERROR",JOptionPane.ERROR_MESSAGE);
                return;
            }
        }
    
      [COLOR="Red"]  private void runReportActionPerformed(java.awt.event.ActionEvent evt) {
            // TODO add your handling code here:
            String tutorOutPut = Double.toString(tarray[0][0]);
            String tutorOutput2 = Double.toString(tarray[0][1]);
            reportArea.append(tutorOutPut + "   " + tutorOutput2);[/COLOR]    }
    
        private void quitActionPerformed(java.awt.event.ActionEvent evt) {
            // Exit program
            System.exit(0);
        }
    Last edited by drgnfire25; 01-11-2011 at 11:34 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Your use of a Scanner that extracts information from System.in together with a GI worries me. Correct me if I'm wrong, but it looks like it should completely freeze your GUI when trying to get input this way. I strongly advise you to get rid of the Scanner object and to get your input in a different way, perhap by having an array of JTextFields or a JTable.

  3. #3
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    It seams to work... Im no programmer but it seams to take the input fine it just wont display it.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Quote Originally Posted by drgnfire25 View Post
    It seams to work... Im no programmer but it seams to take the input fine it just wont display it.
    Sorry to be blunt, but it looks completely borked to me. It's hard to say what's going on without compilable runnable code, but you shouldn't mix GUI and console code the way you're doing it. Also, your for loops are quite strange:

    Java Code:
    for (index = 0; index > 0; index++) {

    Why have a loop that never runs?

  5. #5
    drgnfire25 is offline Member
    Join Date
    Jan 2011
    Posts
    24
    Rep Power
    0

    Default

    Thanks for the scanner info, I almost have it now.
    Last edited by drgnfire25; 01-12-2011 at 03:32 AM.

Similar Threads

  1. Result set not returning values
    By karthikeyan_raju in forum Advanced Java
    Replies: 5
    Last Post: 04-14-2011, 05:24 AM
  2. Returning HexaDecimal Values to an Array???
    By stylishkishore in forum Advanced Java
    Replies: 5
    Last Post: 12-18-2009, 08:04 AM
  3. problem on returning values..
    By kulangotski in forum Advanced Java
    Replies: 11
    Last Post: 03-07-2009, 02:13 AM
  4. Replies: 11
    Last Post: 12-08-2008, 12:29 AM
  5. Returning array problem.
    By Chase in forum New To Java
    Replies: 4
    Last Post: 10-21-2008, 09:07 PM

Posting Permissions

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