📄 createlevelsquentialfile.java
字号:
import java.io.*;
import java.util.*;
public class CreateLevelSquentialFile
{
// instance variables
private ObjectOutputStream output; // output data to file
private String fileName;
Level level; // object to be written to file
String levelName;
String description;
int runway;
float frequency;
int numCrafts;
/**
* Constructor for objects of class CreateSquentialFile
*/
public CreateLevelSquentialFile(String levelName, String description, int runway, float frequency, int numCrafts)
{
// initialise instance variables
this.levelName = this.fileName = levelName;
this.description = description;
this.runway = runway;
this.frequency = frequency;
this.numCrafts = numCrafts;
}
public void openFile()
{
try //open file
{
output = new ObjectOutputStream(new FileOutputStream("H:\\" + getFileName() + ".lvl"));
} // end try
catch(IOException ioException)
{
System.err.println("Error opening file");
}
}
public void setFileName(String f)
{
fileName = f;
}
public String getFileName()
{
return fileName;
}
public void addUserRecord()
{
try
{
level = new Level(levelName, description, runway,frequency, numCrafts);
output.writeObject(level); // write to file
}
catch (IOException ioException)
{
System.err.println("Error writing to file " + ioException.getMessage());
return;
}
} // end add records
public void closeFile()
{
try
{
if (output != null)
output.close();
}
catch (IOException ioExeception)
{
System.err.println("Error closing file");
System.exit(1);
}
}
public String getLevelName()
{
return levelName;
}
public String getDescription()
{
return description;
}
public int getRunways()
{
return runway;
}
public float getFrequency()
{
return frequency;
}
public int getNumcrafts()
{
return numCrafts;
}
} // end class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -