todoapp/src/main/java/de/dhsn/oop/todo.java
2025-06-19 19:43:44 +02:00

36 lines
1.2 KiB
Java

package de.dhsn.oop;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import de.dhsn.oop.data.TodoList;
import de.dhsn.oop.ui.MainWindow;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class todo {
public static void main(String[] args){
List<TodoList> listen = new ArrayList<>();
// try t ope nthe file and read json data if successful
try(JsonReader reader = new JsonReader(new FileReader("./test.json"))) {
Type listType = new TypeToken<List<TodoList>>(){}.getType();
Gson g = new Gson();
List<TodoList> temp = g.fromJson(reader, listType);
//insert all data from json int o state list
listen.addAll(temp);
} catch (FileNotFoundException ignored) {
// ignore file not found --> probably first start and no file present
} catch (IOException e) {
throw new RuntimeException(e);
}
//open the window with the data
new MainWindow(listen);
}
}