import java.io.*;
import java.awt.*;
public class WriteRandFile  extends Frame
{
TextField acct,fName,lName,bal;
Button enter,done;
Label acctLabel,fNameLabel,lNameLabel,balLabel;
RandomAccessFile output;
Record data;
public WriteRandFile()
{
super("Write to random access file");
data = new Record();
try{
output = new RandomAccessFile("credit.dat","rw");
}
catch (IOException e){
System.err.println(e.toString());
System.exit(1);
}
setup();
}
        
public void addRecord()
{
int acctNum = 0;
Double d;
acctNum = (new Integer(acct.getText())).intValue();
try{
if(acctNum > 0 && acctNum <= 100){
data.account = acctNum;
data.firstName = fName.getText();
data.lastName = lName.getText();
d = new Double (bal.getText());
data.balance = d.doubleValue();
output.seek((long)(acctNum-1)*data.size());
data.write(output);
acct.setText(" ");
fName.setText(" ");
lName.setText(" ");
bal.setText(" ");
}
else{
acct.setText("Enter valid account (1-100)");
acct.selectAll();
}
}
catch (IOException e){
System.err.println("Error during write to file\n"+e.toString());
System.exit(1);
}
}
public void setup()
{
resize(300,150);
setLayout(new GridLayout(5,2));
acct = new TextField(20);
acctLabel = new Label("Account Number");
fName = new TextField(20);
fNameLabel = new Label("First Name");
lName = new TextField(20);
lNameLabel = new Label("Last Name");
bal = new TextField(20);
balLabel = new Label("Balance");
enter = new Button("Enter");
done = new Button("Done");
add(acctLabel);
add(acct);
add(fNameLabel);
add(fName);
add(lNameLabel);
add(lName);
add(balLabel);
add(bal);
add(enter);
add(done);
show();
}
public void cleanup()
{
if(!acct.getText().equals(""))
addRecord();
try{
output.close();
}
catch (IOException e){
System.err.println("File not closed properly\n"+e.toString());
System.exit(1);
}
}
public boolean handleEvent(Event event)
{
if(event.id == Event.WINDOW_DESTROY || event.target == done){
cleanup();
hide();
dispose();
System.exit(0);
return true;
}
if(event.target instanceof Button){
if(event.arg.equals("Enter")){
addRecord();
return true;
}
}
return super.handleEvent(event);
}
public static void main(String args[])
{
WriteRandFile accounts = new WriteRandFile();
}
}程序的目的是向credit.dat这个文件中写入数据,随后用Record类的write方法输出这些数据
在编译的过程中会有2个关于Record类的报错,并且说明什么过时的内容
我是初学者~还望各位大哥哥指教!先谢过了