السلام عليكم
لقد قمت بالاستفادة من موضوع سابق في المنتدى لكود يحفظ اللعبة
وقمت بتعديله بما يتناسب مع البرنامج عندي
import java.io.IOException;
import java.io.*;
public class MyGame implements Serializable{
static void saveGame(pegSolitaire peg, String filePath) throws IOException
{
ObjectOutputStream outputStream = null;
try
{
outputStream = new ObjectOutputStream(new FileOutputStream(filePath));
outputStream.writeObject(peg);
}
catch(FileNotFoundException ex)
{
ex.printStackTrace();
}
catch(IOException ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(outputStream != null)
{
outputStream.flush();
outputStream.close();
}
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}
public static pegSolitaire loadGame(String filePath) throws IOException,FileNotFoundException ,ClassNotFoundException {
FileInputStream fileIn = new FileInputStream(filePath);
ObjectInputStream in = new ObjectInputStream(fileIn);
return (pegSolitaire) in.readObject();
}
}حيث ان الكائن هو من نوع pegSolitaire من كلاس تم انشاءه داخل البرنامج
الكود لا يظهر اي اخطاء ولكن لا ينفذ بالمرة
وهذه الاكواد داخل ال
public void actionPerformed(ActionEvent e) {
if(e.getSource()==pegsolitaire.save){
System.out.println ("save");
int answer = JOptionPane.showConfirmDialog(pegsolitaire,"Etes-vous sûr de vouloir enregistrer?", null,JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
try{
MyGame.saveGame(pegsolitaire, "y.svg");
}
catch(IOException ex){
System.out.println ("save");
}
}
}
if(e.getSource()==pegsolitaire.open){
int answer = JOptionPane.showConfirmDialog(
pegsolitaire,
"Etes-vous sûr de vouloir ouvrir le jeu?",
null,
JOptionPane.YES_NO_OPTION);
if (answer == JOptionPane.YES_OPTION) {
try{
MyGame.loadGame("y.svg");
}
catch(IOException ex){
}
catch(ClassNotFoundException ex){
}
}
}
}وما هو امتداد الملف المطلوب؟؟؟


