这是我的作业程序:将applet中的信息写入文件。我的程序也得到了编译和运行,但是文件没有被创建。 任何人都可以告诉我为什么,我会感谢你的帮助!
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();
}
}