| | |
I need ur help:(easy question)
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
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;
}
//===============================================
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;
}
//===============================================
•
•
Join Date: Sep 2008
Posts: 1,598
Reputation:
Solved Threads: 202
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.
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.
•
•
Join Date: Nov 2008
Posts: 332
Reputation:
Solved Threads: 53
if (sc.next().equals(CustomerName)) {
dataList.add("The Searched word is : " + CustomerName + sc.next());
}sc.next() every call returns NEXT value. Use once String any=sc.next() and later use any •
•
Join Date: Dec 2008
Posts: 7
Reputation:
Solved Threads: 0
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;
}
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;
}
![]() |
Similar Threads
- easy question (PHP)
- hopefully easy question (C++)
- Im new and have an easy (I think) question (C++)
- Basic ASP Access question (ASP)
- Hopefully easy question about linking... (C++)
- EASY question? checking for line feed (return) in a html file with C++ (C++)
- A question of RAM (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Pioneers talking about cloud computing secrets at Sun Microsystems Conference
- Next Thread: Game controller
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business chat class classes clear client code codesnippet collections component database defaultmethod development dice dragging ebook eclipse error event exception formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie numbers openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads time tree windows






