my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Building Array with jButton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Building Array with jButton" Watch "Building Array with jButton" New topic
Author

Building Array with jButton

Keith Anderson
Greenhorn

Joined: Apr 19, 2002
Posts: 20
Ok, I am trying to build an Array with two jTextFields, and a jButton.
I.E. I press the Button, and it puts these two fields into position r0,c0 and r0,c1.
The issue I am having, is that when I press the button it (as can be expected) iterates threw the code three times.
I get a full Array. If I entered the numbers 34 and 72 I would get

34, 72
34, 72
34, 72

and it would just re-initialize the Array and do it again when I hit the button.
I need it to let me hit the button three times and feed the Array with three different sets of Variables.
I am guessing I just need to get rid of the for loop.

===


To Be Thus is Nothing<br />Yet<br />To Be Safely Thus
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Why are you using a two-dimensional array and not a one-dimensional array? Why do your comments state "ArrayList" when you're using a 2-D array and not an ArrayList? What is the actual requirements for this assignment?

For better help, you may wish to create a small compilable program that demonstrates your problem and that we can run. I can get you started in this like so:



Feel free to modify this to your heart's content.

Much luck!
Keith Anderson
Greenhorn

Joined: Apr 19, 2002
Posts: 20
Thank you very much for the surrounding code. I am using an IDE, and it would have been very messy if I had cut and pasted the whole thing.
I am using Netbeans, and TextPad++ for development.
===========
Requirements.
===========
I need to generate a program using jButtons, jfields, jArray, jPannel, and jFrame.
I need to create a two dimensional application that will store Money earned and Time spent helping clients.
.. In other words... the two dimensional array--- double array[][].
I need to be able to make a button that quits me out of the application = Easy..
I need to have one button that every time I hit the button it gathers minutes and dollars/cents, and places these items in my array.
===========
I started out with two "for" statements. One for rows, and one for columns.
It seamed more expedient to create just one "for" statement and make the rows static.
=========
Currently whenever I hit the enter info button, it does put the information in the array[0][0],
but the second time I hit the enter information button,
it puts my new information in the same slots of the array[0][0] not iterating to the next row.
Here is the most recent thing I have tried. (I removed the for statement altogether)



Keith Anderson
Greenhorn

Joined: Apr 19, 2002
Posts: 20
In my code, Do I need to move the "for" statement out of the button action section? It only seems to fill up my entire array with the first two items repeated in the array. I do understand why this is happening, but I need to find a way that I can fill in the array , one button push at a time.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Keith Anderson wrote:
===========
Requirements.
===========
I need to generate a program using jButtons, jfields, jArray, jPannel, and jFrame.
I need to create a two dimensional application that will store Money earned and Time spent helping clients.
.. In other words... the two dimensional array--- double array[][].
I need to be able to make a button that quits me out of the application = Easy..
I need to have one button that every time I hit the button it gathers minutes and dollars/cents, and places these items in my array.

Myself, I would like more details regarding the full requirements.What is held by what JTextField, what is stored in the 2D array. The details will lead to the solution.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Building Array with jButton
 
Similar Threads
calculator program help please
How to sum array input.
jbuttons
2D Array problem
Help understanding 2d array output.