Πώς εμφανίζω μια μόνο λέξη από ένα αρχείο στη java
Posted: Sun Feb 07, 2010 3:22 pm
Καλησπέρα!!! Έχω κολλήσει στη java στο εξής:
Θέλω να φτιάξω μια εφαρμογή client-server για αγγελίες σπιτιών.
O client καταχωρεί σε ένα αρχείο:
region num_of_properties (στο συγκεκριμένο region) ipaddress(για να επικοινωνούν οι peers μαζί του)
Στο Server (που λειτουργεί και σαν client) πληκτρολογεί ο χρήστης στο textfield το region που θέλει και ο server του εμφανίζει από το αρχείο την Ip του client που έχει αγγελίες στο συγκεκριμένο region.
Το πρόβλημά μου είναι πως θα κάνω σύγκριση του region με το αντίστοιχο region στο αρχείο και να εμφφανιστεί η αντίστοιχη ip address.
Έχω κάνει αυτά αλλά δεν έχω βρει άκρη.....
Πώς θα τα συπληρώσω αυτά έχω κολλήσει τελείως.. Thanks in advance!!!!
Θέλω να φτιάξω μια εφαρμογή client-server για αγγελίες σπιτιών.
O client καταχωρεί σε ένα αρχείο:
region num_of_properties (στο συγκεκριμένο region) ipaddress(για να επικοινωνούν οι peers μαζί του)
Στο Server (που λειτουργεί και σαν client) πληκτρολογεί ο χρήστης στο textfield το region που θέλει και ο server του εμφανίζει από το αρχείο την Ip του client που έχει αγγελίες στο συγκεκριμένο region.
Το πρόβλημά μου είναι πως θα κάνω σύγκριση του region με το αντίστοιχο region στο αρχείο και να εμφφανιστεί η αντίστοιχη ip address.
Έχω κάνει αυτά αλλά δεν έχω βρει άκρη.....
Code: Select all
tx.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
while(true)
{
try
{
fireader = new FileReader("ads.txt"); //read the file "ads.txt"
bureader = new BufferedReader(fireader); //save its data to the buffered reader
words = new ArrayList<Word>();
int lineNum = 1; // we read first line in start
// delimeters of line only "space"
char [] parse = {' '};
String delims = new String(parse);
String line = bureader.readLine();
// read line while end of file
while(line != null)
{
String [] lineWords = line.split(delims);
displayArea.append("\nPeers with properties at region " + region + " are:" + "\n");
// split the words and create word object
for (int i = 0; i < lineWords.length; i++)
{
// lineNum -> line number i+1--> words index in line
Word w = new Word(lineNum,i+1,lineWords[i]);
words.add(w); // lineWords[i] is word
//print at the text area the corresponding registration
Word ws = words.get(i);
region = ae.getActionCommand(); //get the region that the user has typed
//ιf the typed region exists at the file
[color=#FF0040]if (region.comparesTo(ws.name)) //name tou word me line=1,index=1[/color] {
//appends ip address from file that corresponds to the typed region
[color=#FF0040]displayArea.append(... + " "); //to name tou word me line=1,index = 3[/color] }
/* else
{
displayArea.append("There are no peers with properties at region " + region + ".");
}//end if */
lineNum++; // pass the next line
line = bureader.readLine();
} //end for
} //end while
} //catch io exception, if any
catch (IOException exc) { exc.printStackTrace(); }
} //end while
}
}); //end button Search action listener
// class word for model of every word object
class Word
{
private int lineNum;
private int index;
private String name;
public Word(int lineNum, int index, String name)
{
this.lineNum = lineNum;
this.index = index;
this.name = name;
}
public int getLineNum()
{
return lineNum;
}
public int getIndex()
{
return index;
}
public String getName()
{
return name;
}
} //end class Word