• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Building Array with jButton

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

===
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
reply
    Bookmark Topic Watch Topic
  • New Topic