import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class ReadSequentialFile extends Frame implements ActionListener
{
private TextField accountField,firstNameField,lastNameField,balanceField;
private Button next,done;
private DataInputStream input;
  public ReadSequentialFile()
  {
  super("Musteri dosyas¨n¨ oku");
  try{
   input=new DataInputStream(new FileInputStream("client.dat"));
     } catch(IOException e) { System.err.println("Dosya acilamadi\n"+e.toString());
                              System.exit(1);
                            }
     setSize(300,150);
     setLayout(new GridLayout(5,2));
     add(new Label("Hesap ismi:"));
     accountField=new TextField();
     add(accountField);
     add(new Label("isim : "));
     firstNameField=new TextField(20);
     add(firstNameField);
     add(new Label("soyisim : "));
     lastNameField=new TextField(20);
     add(lastNameField);
     add(new Label("Hesaptaki para : "));
     balanceField=new TextField(20);
     add(balanceField);
     next=new Button("bir sonraki hesap");
     next.addActionListener(this);
     add(next);
     done=new Button("cikis");
     done.addActionListener(this);
     add(done);
     setVisible(true);
  }
  public void readRecord()
  {
  int account;
  String first,last;
  double balance;
    if(!accountField.getText().equals(""))
    {
    try{
       account=input.readInt();
       first=input.readUTF();
       last=input.readUTF();
       balance=input.readDouble();
       accountField.setText(String.valueOf(account));
       firstNameField.setText(first);
       lastNameField.setText(last);
       balanceField.setText(String.valueOf(balance));
       }
       catch(EOFException eof)
       {
        closeFile();
       }
       catch(IOException io)
       {
       System.err.println("Dosyay¨ okurken hata olustu\n"+io.toString());
       System.exit(1);
       }
    }
  }
  public void actionPerformed(ActionEvent e)
  {
  if(e.getSource()==next)
    readRecord();
  else
    closeFile();
  }

  private void closeFile()
  {
  try{
     input.close();
     System.exit(0);
     }
     catch(IOException e)
     {
     System.err.println("Error closing filr\n"+e.toString());
     System.exit(1);
     }
  }

  public static void main(String args[])
  {
  new ReadSequentialFile();
  }
}
