dcsimg
File and Textfield Selection
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   DONE1_D1
Posted On:   Sunday, June 30, 2002 03:50 AM

I have got the following peice of code. The textfile is something like: 1 asss 3 dddd 4 eee 10 fff == I have two things on each line, the first says which TextField and the second one just says what to put in it? How do i write this to the textfield such that Textfield1=asss Textfield3=dddd Textfield4=eee Textfield10=fff N.B:there are about 20 Textfields CODE: public void copy() {try { FileReader file2 = new FileReader("d1.txt"); reading= new BufferedReader(file2); //T1 is Textfield for(int k=0;k <20;k++) { T1[k].setText(reading.readLine()); }    More>>

I have got the following peice of code.


The textfile is something like:
1 asss
3 dddd
4 eee
10 fff
==


I have two things on each line, the first says which TextField and the second one just says what to put in it?
How do i write this to the textfield such that
Textfield1=asss
Textfield3=dddd
Textfield4=eee
Textfield10=fff
N.B:there are about 20 Textfields
CODE:
public void copy()
{try
{ FileReader file2 = new FileReader("d1.txt");
reading= new BufferedReader(file2);
//T1 is Textfield
for(int k=0;k <20;k++)
{ T1[k].setText(reading.readLine());
}
reading.close();
}
catch (FileNotFoundException e)
{ System.err.println("FileStreamsTest: " + e);
}
}

   <<Less

Re: File and Textfield Selection

Posted By:   Anonymous  
Posted On:   Tuesday, July 2, 2002 01:57 PM

You can use the string tokenizer.


public void copy ()
{
try
{
FileReader file2 = new FileReader("d1.txt");
BufferedReader reading = new BufferedReader (file2);
StringTokenizer tokenizer = new StringTokenizer ();
String line = reading.readLine ();

while (line!=null)
{
Int index = Integer.parseInt (tokenizer.nextToken ());
String value = tokenizer.nextToken ());


//use if statements to place values into desired textfields, eg
if (index == 3)
{
T1[index].setText (value);
line = reading.readLine ();
}
}
}

catch (IOException e) {}
}

About | Sitemap | Contact