title: Output of an applet is written into a file
body: <p>This is my assignment program: write information from an applet into a file. My program is getting complied and running as well , but the file is not being created.
  Can anyone please tell me why,I will appreciate the help!</p>
  
  <pre><code>enter code here
  import java.io.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.applet.*;
  public class info extends Applet implements ActionListener 
  {
  String str;
  FileWriter f;
  TextField id,name;
  Label e,i,n;
  String msg;
  public void init()
  {
     e=new Label("Employee info");
     add(e);
     i=new Label("Employee id");
     add(i);
     id=new TextField(10);
     add(id);
     n=new Label("name:");
     add(n);
     name=new TextField(10);
     add(name);
  
   Button submit= new Button("submit");
   Button reset= new Button("reset");
   id.addActionListener(this);
   name.addActionListener(this);
   add(submit);
   add(reset);
   submit.addActionListener(this);
   reset.addActionListener(this);
  }
  
  public void actionPerformed(ActionEvent ae)
  </code></pre>
  
  <p>{
         String str = ae.getActionCommand();</p>
  
  <pre><code>     if(str.equals("submit")) 
      {  
          showStatus("Data Submitted Successfully");
      }
      else if(str.equals("reset")) 
      {
          id.setText("");
          name.setText("");
  
      }
      repaint();
  }
  public void paint(Graphics g)
  </code></pre>
  
  <p>{</p>
  
  <pre><code>    g.drawString("id: "+id.getText(),6,150);
      g.drawString("Name: " + name.getText(), 6, 200);
  </code></pre>
  
  <p>}</p>
  
  <pre><code> public void print() throws IOException
  {
  str=id.getText()+" "+name.getText(); 
  f =new FileWriter("e.txt");
  f.write(str);
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>class output extends info
     {
  
  public static void main(String...s)throws Exception
      {
  
         output obj=new output();
         obj.print();
      }
    }
  </code></pre>