1
爲什麼不是面板加載。我無法確定它是否正確保存。從GUI讀取二進制文件
public void saveParks(JPanel parkingPanel) throws IOException
{
//save parkingPanel JPanel that contains the two car parks
ObjectOutputStream output = new ObjectOutputStream(new FileOutputStream("saveParkPanel.dat"));
output.writeObject(parkingPanel);
System.out.println("saved");
output.close();
}
public void loadParks() throws FileNotFoundException, IOException, ClassNotFoundException
{
ObjectInputStream input = new ObjectInputStream(new FileInputStream("saveParkPanel.dat"));
JPanel parkingPanel = (JPanel)input.readObject();
System.out.println("loaded");
}
}
該類是一個JPanel構造函數,它擴展了JPanel。 – Nebula
是的,但要顯示它,你必須將它添加到'RootPaneContainer'如JFrame。 – davidxxx
試過了,我得到錯誤的sym類型:CarPark.AddVehiclePanel.loadParks 我在哪裏嘗試並調用該方法。它說我需要一個JFrame參數,但是當我把loadParks(框架)當然是框架超出範圍。 – Nebula