saveRule implementation

This commit is contained in:
l.dupuis-burtin 2024-05-30 16:42:36 +02:00
parent 7ae1795911
commit d3efcf8140
2 changed files with 21 additions and 5 deletions

View File

@ -476,8 +476,24 @@ public class Simulator extends Thread {
*/ */
public ArrayList<String> getRule() { public ArrayList<String> getRule() {
//TODO : complete method with proper return //TODO : complete method with proper return
ArrayList<String> arrayline=new ArrayList<String>();
return null; String lineOne="";
for(int i=0;i<ruleSurviveCriteria.size();i++) {
lineOne+=Integer.toString(ruleSurviveCriteria.get(i));
if(i<ruleSurviveCriteria.size()-1) {
lineOne+=";";
}
}
arrayline.add(lineOne);
String lineTwo="";
for(int j=0;j<ruleBirthCriteria.size();j++) {
lineTwo+=Integer.toString(ruleBirthCriteria.get(j));
if(j<ruleBirthCriteria.size()-1) {
lineTwo+=";";
}
}
arrayline.add(lineTwo);
return arrayline;
} }
public void loadRule(ArrayList<String> lines) { public void loadRule(ArrayList<String> lines) {

View File

@ -327,8 +327,7 @@ public class MyInterface extends JFrame {
String fileName=SelectFile(); String fileName=SelectFile();
if (fileName.length()>0) { if (fileName.length()>0) {
ArrayList<String> content = mySimu.getSaveState(); ArrayList<String> content = mySimu.getSaveState();
String[] strArr = Arrays.copyOf(content.toArray(), content.toArray().length, String[].class);
writeFile(fileName, strArr);
} }
} }
@ -336,7 +335,8 @@ public class MyInterface extends JFrame {
String fileName=SelectFile(); String fileName=SelectFile();
if (fileName.length()>0) { if (fileName.length()>0) {
ArrayList<String> content = mySimu.getRule(); ArrayList<String> content = mySimu.getRule();
writeFile(fileName, (String[]) content.toArray()); String[] strArr = Arrays.copyOf(content.toArray(), content.toArray().length, String[].class);
writeFile(fileName, strArr);
} }
} }