I need ur help:(easy question)

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Dec 2008
Posts: 7
Reputation: confusedGirl is an unknown quantity at this point 
Solved Threads: 0
confusedGirl confusedGirl is offline Offline
Newbie Poster

I need ur help:(easy question)

 
0
  #1
Dec 6th, 2008
Hi All

As a beginner, I design a small programm using netbeans(6.1). Actually I designed one class and connected it with several JDialog ,but I find some difficulty with search engin and creating the LinkedList.(how can I connect between them )

main question : if I search fort he customername in the list how can I get all information about this customer . Please modify this code for me . It only works if I search for one word.
I really will appreciate your help !!

// action added to the jBotton
//===============================================

@Action
public int Search4Data() throws FileNotFoundException {
String CustomerName =null;
Vector dataList = new Vector();

String fileName = "d:\\Database.txt";
File fin = new File (fileName);
// get the user input
CustomerName = jTextField2.getText();
Scanner sc = new Scanner(fin);
int count=0;
while(sc.hasNext()){
if(sc.next().equals(CustomerName ))
dataList.add("The Searched word is : "+CustomerName + sc.next());
count++;



jList2.setListData(dataList);
}
return count;
}
//===============================================
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 1,598
Reputation: BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all BestJewSinceJC is a name known to all 
Solved Threads: 202
BestJewSinceJC BestJewSinceJC is offline Offline
Posting Virtuoso

Re: I need ur help:(easy question)

 
0
  #2
Dec 6th, 2008
Why would you use a loop to search? Look at the methods for the Vector class. Particularly, look at the indexOf method. If you override the equals method from the Object class, then use indexOf, it will return the index of the thing you are looking for. So your "search" code would look like this:

while there are still names to search for{
get the next name from the file
check to see if the name you just got is in your Vector using indexOf
if the index != -1 {
Customer customer = Vector(theIndexIndexOfReturned);
}

}

Now, your customer variable will contain the Customer that you were looking for in the Vector.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: I need ur help:(easy question)

 
0
  #3
Dec 6th, 2008
if (sc.next().equals(CustomerName)) {
                dataList.add("The Searched word is : " + CustomerName + sc.next());
            }
In this part of program You are using two times sc.next() every call returns NEXT value. Use once String any=sc.next() and later use any
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 332
Reputation: quuba is on a distinguished road 
Solved Threads: 53
quuba quuba is offline Offline
Posting Whiz

Re: I need ur help:(easy question)

 
0
  #4
Dec 6th, 2008
additional
Post any lines from Database.txt . This is a base to proper answer.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 7
Reputation: confusedGirl is an unknown quantity at this point 
Solved Threads: 0
confusedGirl confusedGirl is offline Offline
Newbie Poster

Re: I need ur help:(easy question)

 
0
  #5
Dec 23rd, 2008
If I want to call A linkedList from the main to the search Jdialog ...It is correct if I write ProjectApp.getApplication().getLinkedList();???


second question : where should I write the above script on the Jdialog??

Third question: how can I add the action the button to edit the information by using this method ?? and where should I put it in the JDialog??
public static boolean editForMaid(LinkedList<maids> list, maids m){

if(searchForMaid(list,m)){
if(list.remove(m))
list.add(m);
return true;
}

return false;
}
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,483
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 515
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: I need ur help:(easy question)

 
0
  #6
Dec 23rd, 2008
These questions make absolutely no sense in the limited context of code that you have posted. You would need to post the relevant code from those other classes if you expect anyone to be able to make a suggestion.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC