Click to See Complete Forum and Search --> : reading?


The One
03-03-2006, 01:32 PM
i created the following code to read a textfile. But i dont know how after reading that textfile to paste wats in it into a textfield in a gui. How do i do it?


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class read {
public static void main (String[] args) throws IOException{
FileReader fr = new FileReader("Salary.txt");
BufferedReader br = new BufferedReader(fr);
String userName = br.readLine();
while (userName != null) {
System.out.println(userName);
userName = br.readLine();
}
br.close();
fr.close();

}
}

geomir
03-05-2006, 08:50 AM
If in your gui source code textfield1 is the name of the textfield
JTextField textfield1=new JTextField("");

and userName is the string variable then you would use the following to set the value of the textfield
textfield1.setText(userName);

The One
03-05-2006, 09:24 AM
ok got it workin.