• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help...  RSS feed

 
Jessie Tan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i doing a seach function... gettin input from the textfield... and seacrh inside an arraylist of a guest list... just want to take out the "name" of all the data from the list to search... i've tried with all these codes, can complie and execute but the search button not working, no respose at all....
Hope someone out there can help...
Thanx alot..

public void actionPerformed (ActionEvent e){

if (e.getSource()==clearBtn) {
clear();
}

if (e.getSource()==searchBtn) {
String nameInput = searchTf.getText();
if (nameInput.length()!=0)
searchName(nameInput); //pass nameInput to method for searching and display result
else
JOptionPane.showMessageDialog(this, "Please enter a name to search", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}
//other codings to perform tasks when other
private void searchName(String nameInput) {
boolean exist=false;
GuestFile r = null;
for (int i=0; i<guestsList.size(); i++) {
r = (GuestFile)guestsList.get(i);
if ((r.getName()).equals(nameInput)) {
exist = true;
//break;
}
if (false)
JOptionPane.showMessageDialog(this, "guest found", "Information", JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(this, "not found", "Error", JOptionPane.ERROR_MESSAGE);
clear();
}
}
public void clear(){
searchTf.setText("");
}
}
[ April 17, 2004: Message edited by: Jessie Tan ]
[ April 17, 2004: Message edited by: Gregg Bolinger ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jessie,
Welcome to JavaRanch!
I suspect you meant this line
if (false)
to say
if (exist)
Otherwise, looks correct.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jessie,
We can all empathise with needing answers "urgently" but specifying so in your subject will most often get your questions igored. We regard everyones questions with the same level of urgency. There are no questions more or less important than others.
I edited your post to remove the word urgent.
I would also recomend that future subjects contain something to do with your question. While this is not a requirement of the Ranch, it is good practice.
 
Jessie Tan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ernest Friedman-Hill:
Hi Jessie,
Welcome to JavaRanch!
I suspect you meant this line
if (false)
to say
if (exist)
Otherwise, looks correct.

Thanx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!