![]() |
inputting in to jfields
So I have this code:
Code:
static ArrayList<String> firstname = new ArrayList();How do you input the text entered to a JField to an ArrayList? Probably an easy question, sorry, I'm new to java. thanks |
Hi ezra,
i'm somewhat learning java as well (haven't really fiddled with it for some time til now). i was able to get the printout for your coding (System.out.println) but the issue that pops up deals with the number 0 showing on top of the console print out..hope this helps Code:
import java.util.ArrayList; |
That will add to the list. The loop doesn't make any sense though; personInput will only be either OK_OPTION or CANCEL_OPTION, so looping it is a horrendously bad idea. All it takes is changing that equality to a different comparison (equality should be avoided in loop conditions in favour of >= or <= (either with or without equals) instead) and then you have an infinite loop.
Its a bad way of doing it, you shouldn't be using a confirm dialog for this, and at the very least not without a frame so you have something to return control to. Dialogs are really more designed for "Are you sure you want to do this?" type actions, inputs into form fields really make more sense on a frame with buttons that have events added on them. I'm not sure what's up with all these arraylists though, these look to me that you should have a single ArrayList<Person> and create a Person class to deal with all those properties. Otherwise you have many disjointed lists that cannot be properly sorted and retain any meaningful relationship. |
| All times are GMT +1. The time now is 09:31 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.