import java.io.*;
import java.util.*;
import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
public class Kontrolle extends Objekteverwaltung {
private ArrayList c1;
/**
* @author Stephan Trapp
*/
public static void main(String[] args) {
// Objects construction
Point point=new Point("Punkt",10,20,30,40);
Linie linie=new Linie("Linie",20,5,10);
Sphere sphere=new Sphere("Kugel",30,3,1,"gelb");
Triangle triangle=new Triangle("Dreieck",40,50,-25,-40,"pink");
// Consctrucion of an ArrayList
ArrayList c = new ArrayList();
c.add(point);
c.add(linie);
c.add(sphere);
c.add(triangle);
boolean ende=false;
mainMenü: while(ende==false){
// Printing of the "Objektverwaltung" with Switch Construct
System.out.println("Die Objekteverwaltung von Grafiken");
System.out.println("=================================="+
"==================================");
System.out.println("\nHauptmenue");
System.out.println("\n(1) Objekte in Datei schreiben");
System.out.println("(2) Objekte auslesen");
System.out.println("(3) Objekte suchen");
System.out.println("(4) Objekt loeschen");
System.out.println("(5) Objekte filtern");
System.out.println("(6) Objekte hinzufügen");
System.out.println("\n(0) Programm beenden");
try{
System.out.println("\nAuswahl: ");
Scanner eingabe=new Scanner(System.in);
int auswahl=eingabe.nextInt();
switch(auswahl){
// Fall 1 Objekte in Datei schreiben
case 1: System.out.println("\n Objekt werden angelegt...");
try{
// Serialisiert Objekt und legt ArrayList und Eingabe in Datei
FileOutputStream fos = new FileOutputStream("test.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
// Schreibt ArrayList in Datei
oos.writeObject((ArrayList) c);
System.out.println(c);
System.out.println("ArrayList wurde in Datei gespeichert");
oos.close();
}
catch(IOException e){
e.printStackTrace();
}
break;
// Fall 2 Liest aus ArrayList
case 2: System.out.println("Objekte laden...");
try{
FileInputStream in=new FileInputStream("test.txt");
ObjectInputStream in1=new ObjectInputStream(in);
c=(ArrayList)in1.readObject();
System.out.println(c.toString());
in1.close();
}
catch(FileNotFoundException e){
System.out.println("Datei nicht gefunden");
}
break;
// Fall 3 Objekt anhand ID suchen
case 3: suchen(c,sphere);
break;
// Fall 4 Objekte Anhand ID in der ArrayList löschen
case 4: löschen(c,point);
break;
// Fall 5 Objekte nach Namen filtern
case 5: filtern(c,linie);
break;
// Fall 6 Objekte zur ArrayList hinzufügen
case 6: System.out.println("Objekt anlegen...");
try{
System.out.println("\nBitte wählen Sie: ");
System.out.println("(1) für Sphere");
System.out.println("(2) für Point");
System.out.println("(3) für Linie");
System.out.println("(4) für Triangle");
System.out.println("(5) Hauptmenü");
System.out.println(" Nummer eingeben :");
Scanner eingabe1=new Scanner(System.in);
int auswahl1=eingabe1.nextInt();
switch(auswahl1){
case 1: hinzufügen1(c,sphere);
break;
case 2: hinzufügen1(c,point);
break;
case 3: hinzufügen1(c,linie);
break;
case 4: hinzufügen1(c,triangle);
break;
case 5: break;
}}
catch(Exception e){
e.printStackTrace();
}
break;
// Fall 0 Exit Program
case 0: System.out.println("\nProgramm wurde beendet");
ende=true;
break;
default: System.out.println("\nEingabe existiert nicht");
}}
catch(Exception e){
System.out.println("");
}
}
}}