the Arrays wouldn't get words typed in TextField whenever i press the Add button..in my gui..need help..please..
Need help with Arrays..and TextFields
Collapse
X
-
Your remark is too vague; about anything can be wrong. Please be a bit moreOriginally posted by rei008the Arrays wouldn't get words typed in TextField whenever i press the Add button..in my gui..need help..please..
specific and show us some relevant code (not all your code please) and tell us
what is happening and what should have happened.
kind regards,
Jos -
sorry..here's the part with the Add button..
well..hmm..let' s see..Array data[] wouldn't get the values from my textfield, using txtEntries.getT ext() and..i have a display button..after pressing Add button..when i press the Display button the values from data[0] - data[2] are displayed along with a number of "null"s depending on my Array size..
so i figured that my Array data[] wouldn't get any value from textfield, using txtEntries.getT ext()..ahahaha. .though i don't know how to solve this prob.
Code:public void actionPerformed(ActionEvent evt) { int nLimit = Integer.parseInt(txtLimit.getText()); String[] data = new String[nLimit]; int ctr2 = Integer.parseInt(txtAvail.getText()); DictionaryTest call = new DictionaryTest(); data[0] = "hey"; data[1] = "weee"; data[2] = "huu"; int ctr3 = 3; if (evt.getActionCommand().equals("ADD")) { if(ctr2 > 0) { data[ctr3] = txtEntry.getText(); ctr3++; ctr2--; txtAvail.setText(String.valueOf(ctr2)); txtEntry.setText(""); } }Comment
-
Remember that System.out.prin tln() is a fine poor man's debugger. Stick a couple
of these lines in your code and print out the value(s) of your variables and any other
value you're interested in. That actionPerformed () method is quite a piece of
convoluted logic that depends on quite a bit of text components and other
components. Can you explain in clear simple English what it is supposed to do?
Also note that your 'data' array is a local variable which means that it is gone
when your actionPerformed () method terminates.
kind regards,
JosComment
-
i see..so, that's why..haha..than ks..Originally posted by JosAHRemember that System.out.prin tln() is a fine poor man's debugger. Stick a couple
of these lines in your code and print out the value(s) of your variables and any other
value you're interested in. That actionPerformed () method is quite a piece of
convoluted logic that depends on quite a bit of text components and other
components. Can you explain in clear simple English what it is supposed to do?
Also note that your 'data' array is a local variable which means that it is gone
when your actionPerformed () method terminates.
kind regards,
Jos
hmm..well..i wanted to add new values into my array by typing a word in the textfield and then add it to the array with the add button..can't seem to find a solution to this anywhere..Comment
-
Neither do I because I still don't understand what your problem is; your descriptionOriginally posted by rei008i see..so, that's why..haha..than ks..
hmm..well..i wanted to add new values into my array by typing a word in the textfield and then add it to the array with the add button..can't seem to find a solution to this anywhere..
of the problem is still utterly vague. One small tip: use an ArrayList<Strin g> instead.
kind regards,
JosComment
-
sorry, i'm not good at explaining stuff..Originally posted by JosAHNeither do I because I still don't understand what your problem is; your description
of the problem is still utterly vague. One small tip: use an ArrayList<Strin g> instead.
kind regards,
Jos
here's that part in my gui..
hmm..is there another way to add an entry into the array using a textfield and a button? i don't know how to solve the 'data' Array local variable problem..haha.. where should i declare my 'data' Array and variables?Comment
-
Make 'data' a member variable, not a local variable. Also make data a simpleOriginally posted by rei008sorry, i'm not good at explaining stuff..
here's that part in my gui..
hmm..is there another way to add an entry into the array using a textfield and a button? i don't know how to solve the 'data' Array local variable problem..haha.. where should i declare my 'data' Array and variables?
List<Integer> object (see the API documentation for the List interface).
kind regards,
JosComment
Comment