Wie kann ich ein Search Engine in Java programmieren?

Code46

Erfahrenes Mitglied
Hi Leute ,

ich muss gerade ein projekt machen wo ich in einem Textfeld die Bahnstation eigeben kann wo ich abfahren möchte und natürlich eine Zielstation.
Die Stationen werden in einem LinkedList gespeichert.

So was ich machen möchte ist,so bald der User einen Buchstaben eingibt soll in dem Textfeld Vorschläge kommen der mit diesem buchstaben anfängt.

Dies ist meine Idee.Jedoch weis ich nicht ob dies zu machen ist und wie man das macht ****?

Wenn ihr mir helfen könntet würde ich mich sehr freuen.

Danke
 
Sorryy für diese frage, aber wie kann ich mir das program angucken. Ich bekomme es nicht hin das program zum laufen zu bringen ****?
 
Die Zwei Klassen in dem Beispiel packst du in zwei seperaten Dateien die du nach der Klasse benennst, also Java2sAutoTextField.java und Java2sAutoComboBox.java, diese Klasse importierst du dann in deinem Projekt.

Und anstatt sowas wie
Java:
JTextField textField = new JTextField();
machst du dann
Java:
Java2sAutoTextField textField = new Java2sAutoTextField(irgendeine_vorher_erstellte_liste_mit_moeglichen_werten);
 
Ich habe eine SLinkedList kann ich die in dem JTextField auf rufen ?

public static void main(String[] args) {
// set up a linked list of 4 integers
SLinkedList greenline = new SLinkedList();
greenline.addFirst("Dejvicka");
greenline.addMid("Hradcanska","Dejvicka");
greenline.addMid("Malostranska","Hradcanska");
greenline.addMid("Staromestska","Malostranska");
greenline.addMid("Mustek","Staromestska");
greenline.addMid("Muzeum","Mustek");
greenline.addMid("Namesti","Muzeum");
greenline.addMid("Jirihoz Podebrad","Namesti");
greenline.addMid("Flora","Jirihoz Podebrad");
greenline.addMid("Zelivskeho","Flora");
greenline.addMid("Stransnicka","Zelivskeho");
greenline.addMid("Skalka","Stransnicka");
greenline.addLast("Depo Hostivar");
printList(greenline);
 
Das weiß ich nicht, es kommt auf die SLinkedList an, ob sie (direkt oder indirekt) das Interface List implementiert.
Zur Not musst du dir das Beispiel umschreiben, dass es darauf passt.
Kannst du mal einen Link zu der Dokumentation der SLinkedList posten?
 
Hier dies ist mein SLinkedList Code:

package linklist;

import java.util.*;


public class SLinkedList {

protected StringNode head;
public SLinkedList() {
head = new StringNode();
}

public static void main(String[] args) {
// set up a linked list of 4 integers
SLinkedList greenline = new SLinkedList();
greenline.addFirst("Dejvicka");
greenline.addMid("Hradcanska","Dejvicka");
greenline.addMid("Malostranska","Hradcanska");
greenline.addMid("Staromestska","Malostranska");
greenline.addMid("Mustek","Staromestska");
greenline.addMid("Muzeum","Mustek");
greenline.addMid("Namesti","Muzeum");
greenline.addMid("Jirihoz Podebrad","Namesti");
greenline.addMid("Flora","Jirihoz Podebrad");
greenline.addMid("Zelivskeho","Flora");
greenline.addMid("Stransnicka","Zelivskeho");
greenline.addMid("Skalka","Stransnicka");
greenline.addLast("Depo Hostivar");
printList(greenline);


SLinkedList yellowline = new SLinkedList();
yellowline.addFirst("Zlicin");
yellowline.addMid("Stodulky","Zlicin");
yellowline.addMid("Luka","Stodulky");
yellowline.addMid("Luziny","Luka");
yellowline.addMid("Hurka","Luziny");
yellowline.addMid("Nove Butovice","Hurka");
yellowline.addMid("Jinonice","Nove Butovice");
yellowline.addMid("Radlicka","Jinonice");
yellowline.addMid("Smichovske Nadrazi","Radlicka");
yellowline.addMid("Andel","Smichovske Nadrazi");
yellowline.addMid("Karlovo Namesti","Andel");
yellowline.addMid("Nardonitrada","Karlovo Namesti");
yellowline.addMid("Mustek","Nardonitrada");
yellowline.addMid("NR","Mustek");
yellowline.addMid("Florence","NR");
yellowline.addMid("Krizikova","Florence");
yellowline.addMid("Invalidovna","Krizikova");
yellowline.addMid("Palmovka","Invalidovna");
yellowline.addMid("CM","Palmovka");
yellowline.addMid("Vysocanska","CM");
yellowline.addMid("Kolbenova","Vysocanska");
yellowline.addMid("Hloubetin","Kolbenova");
yellowline.addMid("Rajska Zahrada","Hloubetin");
yellowline.addLast("Cerry Most");
printList(yellowline);

SLinkedList redline = new SLinkedList();
redline.addFirst("Ladvi");
redline.addMid("Kobylisy","Ladvi");
redline.addMid("Nadrazi Holesovic","Kobylisy");
redline.addMid("Vltavska","Nadrazi Holesovic");
redline.addMid("Florence","Vltavska");
redline.addMid("Hlavni","Florence");
redline.addMid("Muzeum","Hlavni");
redline.addMid("I.P.Pavlova","Muzeum");
redline.addMid("Vysehrad","I.P.Pavlova");
redline.addMid("Prazskeho Povstani","Vysehrad");
redline.addMid("Pankrac","Prazskeho Povstani");
redline.addMid("Budejovicka","Pankrac");
redline.addMid("Kacerov","Budejovicka");
redline.addMid("Roztyly","Kacerov");
redline.addMid("Chodov","Roztyly");
redline.addMid("Opatov","Chodov");
redline.addLast("Haje");
printList(redline);


}

//add a new node to the head of the list
private void addFirst(String element) {
// make variable head point to new node
head = new StringNode(element,head);
}

private void addLast(String element) {
StringNode tail;
tail = head;
while (tail.getNext() != null) {
tail = tail.getNext();
}
//insert new node at end of list
tail.setNext( new StringNode(element));
}

//add a new node after position of curnode
private void addMid(String element, String entryafter) {
StringNode curnode;
curnode = head;
//go to last node and remember previous node at all times
while (curnode != null && curnode.getElement() != entryafter) {
curnode = curnode.getNext();
}
//if first occurrence of element entryafter was located then insert new node
if (curnode != null) {
StringNode newnode = new StringNode(element,curnode.getNext());
curnode.setNext(newnode);
}
}

private boolean isEmpty() {
return head == null;
}

private void removeFirst() {
StringNode oldhead;
oldhead = head;
//remove first node from linked list
if (head != null) {
head = head.getNext();
oldhead.setNext(null);
}
else {
throw new NoSuchElementException();
}
}

private void removeLast() {
StringNode temp, previous;
temp = head;
previous = temp;
//go to last node and remember previous node at all times
while (temp != null && temp.getNext() != null) {
previous = temp;
temp = temp.getNext();
}
if (previous != null) {
//remove last node
previous.setNext(null);
}
else {
throw new NoSuchElementException();
}
}

//very similar to removeLast except we are looking for element i
private void removeMid(String element) {
StringNode temp, previous;
temp = head.getNext();
previous = null;
//go to node containing element and rermember previous node at all times
while (temp.getElement() != element && temp.getNext() != null) {
previous = temp;
temp = temp.getNext();
}
if (previous != null && temp.getNext() != null) {
//not first or last node so we can remove node defined by temp.
// set the previous node to that after temp
previous.setNext(temp.getNext());
temp.setNext(null);
}
else {
throw new NoSuchElementException();
}
}
public static void printList(SLinkedList thelist) {
StringNode temp;
if(thelist.isEmpty())
System.out.println("List is empty");
else {
temp = thelist.head;
while (temp != null) {
System.out.print(temp.getElement()+" ");
temp = temp.getNext();
}
System.out.println();
}
}

}
 
Zurück