hi, prog below reads a text file and displays the info on 5
JTextField(s). I am using BufferedReader to read from the file and StringTokenizer to break the strings.

I'm having problem updating a specific string. For instance the info from file displays on 5 diff JTextFields -
First name, Second Name, and 3 other fields. Now i want to edit the 1st JTextField and write back to the file, updating only the first string or deleting the whole line.

thanx in advance.



import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.*;

class disRecord extends JDialog
{
Vector listVect;
JList printerList;
JScrollPane listPane;
String fileName = "custAccount.txt";
Container cnt;
JTextField valueField;
JButton updateAcc;
JButton view;
BufferedReader inFile;
JTextField t1, t2, t3, t4, t5, t6, t7;
JLabel l1, l2, l3;


BasicArrowButton lArrow, rArrow;


disRecord(JFrame f)
{
super(f);

setTitle("Account Customer List");


setSize(565, 300); // width, height
setLocation(320, 140); // where to display
nextMenu();
displayPrinter();
setResizable(false);
setVisible(true);


}


public void displayPrinter()//constructor
{
cnt = getContentPane();
cnt.setLayout(new BorderLayout());

printerList = new JList();
valueField = new JTextField(null, 10);
view = new JButton("View Details");
updateAcc = new JButton("Update Account");
lArrow = new BasicArrowButton(BasicArrowButton.WEST);
rArrow = new BasicArrowButton(BasicArrowButton.EAST);
l1 = new JLabel("Current Account: ");
l1.setFont(new Font( "TimesRoman", Font.BOLD, 23 ) );
l1.setForeground(Color.magenta);
l2 = new JLabel("Saving Account: ");
l2.setFont(new Font( "TimesRoman", Font.BOLD, 23 ) );
l2.setForeground(Color.magenta);
l3 = new JLabel("Account Holder: ");
l3.setFont(new Font( "TimesRoman", Font.BOLD, 23 ) );
l3.setForeground(Color.magenta);

t1 = new JTextField(10);
t2 = new JTextField(10);
t3 = new JTextField(10);
t4 = new JTextField(10);
t5 = new JTextField(10);

setVisible(true);
try {
listVect = new Vector();

BufferedReader br = new BufferedReader(new FileReader(fileName));
String line ;
while( (line = br.readLine()) != null)
{
StringTokenizer t = new StringTokenizer(line, ", ");

String printerName = t.nextToken();
listVect.addElement( printerName );

}
br.close();
}
catch (Exception err)
{
err.printStackTrace();
}
printerList.setListData( listVect );

// only one item can be selected
printerList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
printerList.setVisibleRowCount(5);
Font displayFont = new Font("Serif", Font.BOLD, 20);
printerList.setFont( displayFont );

JPanel pnl1 = new JPanel();
pnl1.setLayout(new FlowLayout());
pnl1.setBackground(Color.blue);
cnt.add("North", pnl1);
pnl1.add(new JScrollPane(printerList));
pnl1.add(view);

JPanel pnl2 = new JPanel();
pnl2.setLayout(new GridLayout(3,3));
pnl2.setBackground(Color.yellow);
cnt.add("West", pnl2);

pnl2.add(l3);
pnl2.add(t1);
pnl2.add(t2);
pnl2.add(l1);
pnl2.add(t3);
pnl2.add(t4);
pnl2.add(l2);
pnl2.add(t5);
pnl2.add(updateAcc);

t3.setToolTipText ("Your Current Balance");
t4.setToolTipText ("Your Credit Limit");
t5.setToolTipText ("Your Current Balance");
updateAcc.setToolTipText ("Edit Any Fields and Then Press The Button To Alter Your File");


JPanel pnl3 = new JPanel();
pnl3.setLayout(new GridLayout(1, 2, 30, 30));
cnt.add("South", pnl3);
pnl3.setBackground(Color.black);
pnl3.add(lArrow);
pnl3.add(rArrow);

pageDirection pageDir = new pageDirection();
lArrow.addActionListener(pageDir);
rArrow.addActionListener(pageDir);

vCustDetails viewCD = new vCustDetails();
view.addActionListener(viewCD);

// conversion
printerList.addListSelectionListener(new ListSelectionListener(){
public void valueChanged (ListSelectionEvent lev)
{
if (!lev.getValueIsAdjusting())
t1.setText(printerList.getSelectedValue().toString());
// nPg.t1.setText("kk");
//nPg = new nextPage(new JFrame());


}
}
);
}



private class pageDirection implements ActionListener{
public void actionPerformed( ActionEvent pDir )
{

if (pDir.getSource() == lArrow)
{
toBack();
}

if (pDir.getSource() == rArrow)
{
toFront();
}
}
}

private class vCustDetails implements ActionListener{
public void actionPerformed (ActionEvent evt)
{
if(evt.getSource() == view)
{
//t1.setText(dRec.valueField.getText());

try{
inFile = new BufferedReader(
new FileReader(fileName));
}

catch (IOException e) {
return;
}

//reading the file
try{
String line;
boolean found = false;
while ((( line = inFile.readLine()) !=null) && (! found))
{
//tokens split on comma and spaces set in the file (quazi, anwar)
StringTokenizer tokens = new StringTokenizer( line, ", ");

String nameInFile = tokens.nextToken();

if (t1.getText().equals(nameInFile))
{
found = true;
//tokens.nextToken();
t2.setText(tokens.nextToken()); // put the first string
tokens.nextToken();
t3.setText(tokens.nextToken()); // put the second string
t4.setText(tokens.nextToken());
tokens.nextToken();
t5.setText(tokens.nextToken());
}
}
inFile.close(); // close the file
}
catch (IOException e)
{
System.err.println("Error reading file "+ fileName + ": " + e.toString() );
System.exit(1);
}
}
}
}