473,378 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Need help with Arrays..and TextFields

7
the Arrays wouldn't get words typed in TextField whenever i press the Add button..in my gui..need help..please..
Nov 1 '08 #1
8 1965
JosAH
11,448 Expert 8TB
the Arrays wouldn't get words typed in TextField whenever i press the Add button..in my gui..need help..please..
Your remark is too vague; about anything can be wrong. Please be a bit more
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
Nov 1 '08 #2
rei008
7
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.getText() 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.getText()..ahahaha..though i don't know how to solve this prob.


Expand|Select|Wrap|Line Numbers
  1. public void actionPerformed(ActionEvent evt)     {
  2.        int nLimit = Integer.parseInt(txtLimit.getText());             
  3.        String[] data = new String[nLimit];     
  4.        int ctr2 = Integer.parseInt(txtAvail.getText()); 
  5.        DictionaryTest call = new DictionaryTest();     
  6.        data[0] = "hey";         
  7.        data[1] = "weee";         
  8.        data[2] = "huu";     
  9.        int ctr3 = 3;                   
  10.    if (evt.getActionCommand().equals("ADD")) {
  11.          if(ctr2 > 0) {             
  12.          data[ctr3] = txtEntry.getText();        
  13.          ctr3++;             
  14.          ctr2--;             
  15.          txtAvail.setText(String.valueOf(ctr2));               
  16.          txtEntry.setText("");                          
  17.    }                      
  18. }
  19.  
Nov 1 '08 #3
JosAH
11,448 Expert 8TB
Remember that System.out.println() 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
Nov 1 '08 #4
rei008
7
Remember that System.out.println() 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
i see..so, that's why..haha..thanks..

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..
Nov 1 '08 #5
JosAH
11,448 Expert 8TB
i see..so, that's why..haha..thanks..

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..
Neither 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<String> instead.

kind regards,

Jos
Nov 1 '08 #6
rei008
7
Neither 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<String> instead.

kind regards,

Jos
sorry, 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?
Nov 1 '08 #7
JosAH
11,448 Expert 8TB
sorry, 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?
Make 'data' a member variable, not a local variable. Also make data a simple
List<Integer> object (see the API documentation for the List interface).

kind regards,

Jos
Nov 1 '08 #8
rei008
7
Make 'data' a member variable, not a local variable. Also make data a simple
List<Integer> object (see the API documentation for the List interface).

kind regards,

Jos

thank you very much..i'll try changing my codes..
Nov 1 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Filips Benoit | last post by:
Dear All, After copying a record using an Stored procedure all textfields (nvarchar) has max lenght ! See VBA-code and SP below VBA-code tos execute SP
3
by: Bobbak | last post by:
Hello All, I was wondering if it is at all possible to have a single combo box update multiple fields in a single record. For example I have created an Employee Info form, and in that form there's...
0
by: jac | last post by:
Hey, this.CmbDataSource = SoortKwijtingList.Items; // Arraylist this.Cmb.DisplayMember = "Omschrijving"; this.Cmb.ValueMember = "Id"; this.Cmb.SelectedIndex = -1; (short description : I...
0
by: chandutp | last post by:
hi i am new to this forum can i populate datagrid items of asp page to another asp page having textfields. in this datagrid userId is the index key by which it referenced.and i am using edit...
6
by: eureka | last post by:
Hi friends, I am developing a web application using Jsp and JS. I have a main Jsp page(Jsp1).Inside it I have an iframe having an Html- table which is created dynamically and contains all...
6
blazedaces
by: blazedaces | last post by:
Hey, so here's an example of what I want to do: This "window" if you will, or simple gui, will accept an ArrayList<String> and in turn spit out for every one of them a checkbox and a text field...
3
by: carlos123 | last post by:
Ok, im having EXTREME problems, with arraylists, i simply dont understand them, yes i have read your article. Would someone just take a look at this code, i know it sucks. Look at the areas that say...
3
by: bravephantom | last post by:
In my project "scientific calculator", im using 2 textfields in my GUI app. the problem now (or actually what i dislike) is the user has to use the 2 textfields even if he needs a function of only 1...
1
by: javatech007 | last post by:
I am trying to save data into an array from JTextFields but dont know how to go about it. I have a number of textfields to enter information into it. I dont know where to start with how to use arrays...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.