• Post Reply Bookmark Topic Watch Topic
  • New Topic

Info from textfield to arraylist on button click?

 
Ian Tail
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm learning Java, and this is the first GUI I'm building.

I'm stuck on getting the info that is entered in the JTextFields to be saved to a particular ArrayList (depending on key words) when the JButton (save) is clicked.

Any help would be amazing (Apologies in advance, of the state of my code, as I said, I'm at teh early stages of learning and still piecing things together)

Below is the chunk of code where I'm having the problem (I think), I can post all my classes/code if it'd help?

 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something wrong about that method, I am afraid. You shouldn't be taking input from a text component and using it to direct actions. What happens if you spell the input wrongly? Or enter “heat”, for example? I would suggest you should consider 5 buttons for the 5 actions. Or you can use a combo box or a list (the display sort not the data structure), which you can read about in the Java™ Tutorials 1 2. Or you can pass the text and use a Map to find where to put the note in the board class using some sort of mapping.
There is also something wrong with having public fields which you can access directly. Also why do those methods in the board class appear to be static?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!