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;
}
//===============================================

Recommended Answers

All 5 Replies

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.

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

additional
Post any lines from Database.txt . This is a base to proper answer.

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;
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.