schLabPanel.add(schLab[i]);
schLabPanel.add(schTf[i]);
}
for (int i = 0; i < 2; i++) {
schBtn[i] = new Button(schBtnName[i]);
schBtn[i].addActionListener(this);
schBtnPanel.add(schBtn[i]);
}
schBtn[1].setActionCommand("search");
searchFrame.add(schLabPanel, BorderLayout.CENTER);
searchFrame.add(schBtnPanel, BorderLayout.SOUTH);
searchFrame.pack();
searchFrame.setLocationRelativeTo(mainFrame);
/**
* IO operation object
*/
ioo = new IOOperation();
plane = ioo.getAllPlane();
}
文件操作部分
[java]
public class IOOperation {
private File file = new File("E:\\wenjianyuan\\info");
public IOOperation() {
try {
if (!file.exists()) {
file.createNewFile();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*/
public void write(Plane[] wPlane) {
try {
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream objOut = new ObjectOutputStream(fos);
objOut.writeObject(wPlane);
objOut.close();
fos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* read all informations from the file
*/
public Plane[] getAllPlane() {
Plane[] plane = new Plane[100];
try {
if (file.length() > 0) {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois=new ObjectInputStream(fis);
plane= (Plane[]) ois.readObject();
ois.close();
fis.close();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return plane;
}
}
感兴趣的朋友可以到:http://up.2cto.com/2012/0330/20120330102313543.rar下载完整代码。
摘自 Yanghai