//Search Choicelist buildConstraints(constraints, 0, 1, 2, 1, 0, 10); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(searchlist, constraints); searchlist.addItem(" by First Name "); searchlist.addItem(" by Last Name "); searchlist.addItem(" by Phone Number "); searchlist.addItem(" by Street Name "); add(searchlist);
public void handleFirstName(){ String results = textfield.getText(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < FirstNames.length; i++){ if(FirstNames[i].equals(results)){ buf.append(complete[i] + "\n");} else{ } } resultsdisplay.setText(buf.toString()); }
public void handleLastName(){ String results = textfield.getText(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < LastNames.length; i++){ if(LastNames[i].equals(results)){ buf.append(complete[i] + "\n");} else{ } } resultsdisplay.setText(buf.toString()); }
public void handlePhone(){ String results = textfield.getText(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < Phone.length; i++){ if(Phone[i].equals(results)){ buf.append(complete[i] + "\n");} else{ } } resultsdisplay.setText(buf.toString()); }
public void handleAdress(){ String results = textfield.getText(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < Address.length; i++){ if(Address[i].equals(results)){ buf.append(complete[i] + "\n");} else{ } } resultsdisplay.setText(buf.toString()); } }
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
posted
0
Hmmm... your code would be a lot easier to read (and thus, more likely to get useful responses from readers) if it were indented properly. Use the [ code ] tag to maintain indentation; read about it in our FAQ (see question 4). Also, we really don't need all the GUI code here - your question only relates to the search utility; that's the only part we need to see. Anyway, I eventually found that you were identifying a match using the String equals() method. The fix is simple - use equalsIngoreCase() instead. This is hardly the most efficient way to search, if the list of data is large, but it's easy enough to implement. To get wildcard capability though - that's more complex. You could implement something yourself, using String methods like startsWith() and endsWith(), but this gets complicated pretty quickly. (It might be a good idea to prohibit users from entering more than one wildcard in a string - that will reduce the complexity for you somewhat.) Note that startsWith() and endsWith() don't come with ignoreCase versions, so instead you'll probably want to convert all strings to lower case (or upper case if you prefer) before you do any searching. Alternately, it may be better or easier to find an existing regex package which contains this functionality, and incorporate it into your code. Using google I found a nice collection of related links here. Worth looking into...
"I'm not back." - Bill Harding, Twister
jim, valenta
Ranch Hand
Joined: Mar 16, 2001
Posts: 47
posted
0
jim thanks. I really appreciate it. Unfortunately I tried your link but it was really bad, barely a link that worked. I will try some more searching but I have done quite a bit and most searches dont work on just HTML and text documents only.