0

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!

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)

{ String str = ae.getActionCommand();

     if(str.equals("submit")) 
    {  
        showStatus("Data Submitted Successfully");
    }
    else if(str.equals("reset")) 
    {
        id.setText("");
        name.setText("");

    }
    repaint();
}
public void paint(Graphics g)

{

    g.drawString("id: "+id.getText(),6,150);
    g.drawString("Name: " + name.getText(), 6, 200);

}

 public void print() throws IOException
{
str=id.getText()+" "+name.getText(); 
f =new FileWriter("e.txt");
f.write(str);
}

}

class output extends info
   {

public static void main(String...s)throws Exception
    {

       output obj=new output();
       obj.print();
    }
  }
0ndre_
  • 3,577
  • 6
  • 26
  • 44
  • `void main()` is what gets called in Java _applications_, not applets. – Tim Biegeleisen Sep 17 '16 at 16:38
  • You should make the call to `print()` from your `init()` method, or somewhere else where the applet code will actually reach. Better yet, stop using applets as they have been deprecated (i.e. they are an obsolete technology). – Tim Biegeleisen Sep 17 '16 at 16:40
  • 2
    Possible duplicate of [How to write to a file in applets in java?](http://stackoverflow.com/questions/17388523/how-to-write-to-a-file-in-applets-in-java) – Robert Sep 17 '16 at 16:44

0 Answers0