Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28
  1. #21
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Passing an array to another class in a JFrame

    Well, walk through what your current code does:

    • A user enters a number into the number JTextField
    • The user then presses the jbtEnter JButton
    • This calls the EnterListener's actionPerformed method
    • This loops a bit less than 50 times (your for loop is bad in that you increment the counter variable, i, inside of the loop, something that you should almost never do).
    • In the for loop, you get the String held by the number JTextField, convert it to an int, and add it into an ArrayList<Integer>, and again, you do this *many* times in a row, about 25 times.


    This is what i'm asking you -- do you want to add the same number into the ArrayList 25 times? If not, get rid of that for loop.

  2. #22
    George5432 is offline Member
    Join Date
    May 2012
    Posts
    20
    Rep Power
    0

    Default Re: Passing an array to another class in a JFrame

    I did erase the for loop

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

    Default Re: Passing an array to another class in a JFrame

    Quote Originally Posted by George5432 View Post
    I did erase the for loop
    Good, but the message is the same: walk through your code mentally to figure out what it's doing each step of the way.

  4. #24
    George5432 is offline Member
    Join Date
    May 2012
    Posts
    20
    Rep Power
    0

    Default Re: Passing an array to another class in a JFrame

    thanks for trying to help

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

    Default Re: Passing an array to another class in a JFrame

    Quote Originally Posted by George5432 View Post
    thanks for trying to help
    You're welcome. So you've got things solved now? If you have further questions, don't hesitate to ask.

  6. #26
    George5432 is offline Member
    Join Date
    May 2012
    Posts
    20
    Rep Power
    0

    Default Re: Passing an array to another class in a JFrame

    Not complete yet. Still having some issues with the loop to make it stop at 50 but working on it.

  7. #27
    George5432 is offline Member
    Join Date
    May 2012
    Posts
    20
    Rep Power
    0

    Default Re: Passing an array to another class in a JFrame

    Any advice on the loop portion to stop at 50?

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

    Default Re: Passing an array to another class in a JFrame

    Quote Originally Posted by George5432 View Post
    Any advice on the loop portion to stop at 50?
    Sure -- check the size of the ArrayList (it has a method to let you do that), and not accept any more input if the size is 50 or above.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Passing 2 dementional array to a new class
    By anonymous in forum New To Java
    Replies: 4
    Last Post: 03-15-2011, 11:07 PM
  2. Passing array to model class
    By keshaba in forum IntelliJ IDEA
    Replies: 0
    Last Post: 04-20-2010, 01:43 PM
  3. Replies: 6
    Last Post: 04-12-2010, 11:33 AM
  4. Passing data from one JFrame to another JFrame
    By tarami in forum New To Java
    Replies: 3
    Last Post: 08-06-2009, 05:44 PM
  5. Replies: 8
    Last Post: 03-21-2009, 09:34 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
  •