import java.io.*;
import java.beans.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class simFinJFrame extends JFrame implements ActionListener
{

	simFinJPanel fjp, fjp1, fjp2, fjp3;
	JLabel fjt1,fjt2;
	JButton fjb1, fjb2;

	car myCar;
	track myTrack;
	obstacle myObstacle;

	int result;

	int[] inputL;
	int[] inputR;
	int[] inputD;
	int[] inputU;
	
	public simFinJFrame (int inputResult, obstacle inputObstacle, track inputTrack, car inputCar, int[] inputInputL, int[] inputInputR, int[] inputInputD, int[] inputInputU)
	{
		super ("Game Over");

		result = inputResult;

		myObstacle = inputObstacle;
		myTrack = inputTrack;
		myCar = inputCar;
		
		inputL = inputInputL;
		inputR = inputInputR;
		inputD = inputInputD;
		inputU = inputInputU;


//------------------------------------------------------
// Create components: Jpanel, JLabel and JTextField
		if (result == 0)
		{
			fjt1 = new JLabel("Your car expoloded");
		}
		else
		{
			fjt1 = new JLabel("You Finished!");
		}

		JLabel fjt2 = new JLabel("Would you like to save this run?");	 		 

		fjp = new simFinJPanel();
    		fjp1 = new simFinJPanel();
	    	fjp2 = new simFinJPanel();
		fjp3 = new simFinJPanel();
    	  	
		fjb1 = new JButton("Save");
		fjb2 = new JButton("Cancel");

//-----------------------------------------------------------------
//------------------------------------------------------
// Choose a Layout for JPanel and 
// add components to Jpanel according to layout 

		fjp.setLayout(new GridLayout(3,1,0,0));

   		fjp1.add(fjt1);
		fjp2.add(fjt2);	
		fjp3.add(fjb1);	
		fjp3.add(fjb2);
		
		
		fjp.add(fjp1);
		fjp.add(fjp2);
		fjp.add(fjp3);
		
   		fjb1.addActionListener(this); 
    		fjb2.addActionListener(this);

//------------------------------------------------------
// Choose a Layout for JFrame and 
// add Jpanel to JFrame according to layout    	
		getContentPane().setLayout(new GridLayout());
		getContentPane().add(fjp,"Center");
//------------------------------------------------------
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize (300, 150);
		show();
	}
	
// actionPerformed
    

    public void actionPerformed(ActionEvent event)
	{
	
	
	 	Object obj = event.getSource();
	       	 
	     	if (obj == fjb1)
	    	{
			//SAVE
			export();
			this.dispose();

	     	}
		else if (obj == fjb2)
		{
			//Don't Save
			this.dispose();
		}
	}

	public void export()
	{
		System.out.println("Export");

		myXML_Creator xml = new myXML_Creator();

    		try {
   	        	xml.Create("Simulation");
   	          	//xml.WriteObject(myObstacle);
			xml.WriteObject(myObstacle.objectsImageNumber);			
			xml.WriteObject(myObstacle.objectsPosX);
			xml.WriteObject(myObstacle.objectsPosY);
			xml.WriteObject(myObstacle.objectsSizeX);
			xml.WriteObject(myObstacle.objectsSizeY);

   	          	//xml.WriteObject(myTrack);
			xml.WriteObject(myTrack.trackNumber);

   	          	//xml.WriteObject(myCar);
			xml.WriteObject(myCar.carNumber);

		  	xml.WriteObject(inputL);
		  	xml.WriteObject(inputR);
		  	xml.WriteObject(inputD);
		  	xml.WriteObject(inputU);
   	          	xml.Close();
         	}
       	 	catch(FileNotFoundException e) {e.printStackTrace();}
	}
    
}
