import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class CreateSequentialFile extends Frame implements ActionListener
{
private TextField accountField,firstNameField,lastNameField,balanceField;
private Button enter,done;
private DataOutputStream output;
  public CreateSequentialFile()
  {
  super("Musteri dosyasi ac");
  try{
   output=new DataOutputStream(new FileOutputStream("client.dat"));
     } catch(IOException e) { System.err.println("File not opened properly\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);
     enter=new Button("Gir");
     enter.addActionListener(this);
     add(enter);
     done=new Button("cikis");
     done.addActionListener(this);
     add(done);
     setVisible(true);
  }
  public void addRecord()
  {
  int accountNumber=0;
  Double d;
    if(!accountField.getText().equals(""))
    {
    try{
       accountNumber=Integer.parseInt(accountField.getText());
       if(accountNumber>0)
       {
       output.writeInt(accountNumber);
       output.writeUTF(firstNameField.getText());
       output.writeUTF(lastNameField.getText());
       d=new Double(balanceField.getText());
       output.writeDouble(d.doubleValue());
       }
       accountField.setText("");
       firstNameField.setText("");
       lastNameField.setText("");
       balanceField.setText("");
       }
       catch(NumberFormatException nfe)
       {
       System.err.println("Hesap numarasi tamsayi degisken olamalidir");
       }
       catch(IOException io)
       {
       System.err.println("Dosyaya yazarken hata olustu\n"+io.toString());
       System.exit(1);
       }
    }
  }
  public void actionPerformed(ActionEvent e)
  {
  addRecord();
    if(e.getSource()==done)
    {
    try{ output.close();}
    catch(IOException io)
    {
    System.err.println("Dosya kapatilamadi\n"+io.toString());
    }
    System.exit(0);
    }
  }
  public static void main(String args[])
  {
  new CreateSequentialFile();
  }
}
