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

public class optionsJFrame extends JFrame implements ItemListener, ActionListener
{

	JComboBox jcb1,jcb2,jcb3;
	optionsJPanel mjp, mjp2;
	JLabel jt1,jt2,jt3,jt5;
	JButton jb1;

	car myCar;
	track myTrack;
	obstacle myObstacle;
	
	public optionsJFrame (obstacle inputObstacle, track inputTrack, car inputCar)
	{
		super ("Simulation Options");
		myObstacle = inputObstacle;
		myTrack = inputTrack;
		myCar = inputCar;
//------------------------------------------------------
// Create components: Jpanel, JLabel and JTextField
		JLabel jt1 = new JLabel("                              Select a Vehicle Type");
		JLabel jt2 = new JLabel("                         Select Weather Conditions");		
		JLabel jt3 = new JLabel("                                   Select a Course");
		JLabel jt5 = new JLabel("                             Vehicle Simulation 1.0");  		 

    	mjp  = new optionsJPanel();
    	mjp2 = new optionsJPanel();
    	
    	jcb1 = new JComboBox();
    	jcb1.addItemListener(this);
    	jcb1.addItem("Buggy");
    	jcb1.addItem("Sports Car");
    	jcb1.addItem("Truck");
    	
    	jcb2 = new JComboBox();
    	jcb2.addItemListener(this);
    	jcb2.addItem("Dry");
    	jcb2.addItem("Snow");
    	jcb2.addItem("Wet");

    	jcb3 = new JComboBox();
    	jcb3.addItemListener(this);
    	jcb3.addItem("Road Course");
    	jcb3.addItem("Dirt Track");
    	jcb3.addItem("Jungle");
    	
	    jb1 = new JButton("Continue");

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

	mjp.setLayout(new GridLayout(4,20,20,20));

   	mjp.add(jt1);
		mjp.add(jcb1);
	mjp.add(jt2);	
		mjp.add(jcb2);
	mjp.add(jt3);	
		mjp.add(jcb3);
	mjp.add(jt5);
		
		
	mjp2.add(jb1);
		
    jb1.addActionListener(this); 
//		
	mjp.add(mjp2);
//		
//		
//------------------------------------------------------
// Choose a Layout for JFrame and 
// add Jpanel to JFrame according to layout    	
		getContentPane().setLayout(new GridLayout());
		getContentPane().add(mjp,"Center");
//		getContentPane().add(mjp2,"Center");
//------------------------------------------------------
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize (600, 250);
		show();
	}
	
// actionPerformed
    public void itemStateChanged(ItemEvent event) 
    {
//-----------------------------------------------------------------------    	
      	 if (event.getSource()==jcb1)
      	 {
     	 	if (event.getStateChange()==ItemEvent.SELECTED) 
     	 	{
     	 	 	
     	 	 	System.out.println("Selected vehicle is a "+ jcb1.getSelectedItem());

			if (jcb1.getSelectedItem() == "Buggy")
			{
				myCar.changeCar(1);
			}
			else if (jcb1.getSelectedItem() == "Sports Car")
			{
				myCar.changeCar(2);
			}
			else if (jcb1.getSelectedItem() == "Truck")
			{
				myCar.changeCar(3);
			}
     	    		else {}

     	    }
     	 }
//---------------------------------------------------------------------------     	 
        if (event.getSource()==jcb2)
      	 {
     	 	if (event.getStateChange()==ItemEvent.SELECTED) 
     	 	{
     	 	 System.out.println("Selected Weather is "+ jcb2.getSelectedItem());

     	    		if (jcb2.getSelectedItem() == "Dry")
			{
				myTrack.changeWeather(1);
			}
			else if (jcb2.getSelectedItem() == "Snow")
			{
				myTrack.changeWeather(2);
			}
			else if (jcb2.getSelectedItem() == "Wet")
			{
				myTrack.changeWeather(3);
			}
     	    		else {}
     	    
     	    }
     	 }   	 
//---------------------------------------------------------------------------     	 
         if (event.getSource()==jcb3)
      	 {
     	 	if (event.getStateChange()==ItemEvent.SELECTED) 
     	 	{
     	 	 System.out.println("Selected Course is "+ jcb3.getSelectedItem());
     	    		
			if (jcb3.getSelectedItem() == "Road Course")
			{
				myTrack.changeType(1);
			}
			else if (jcb3.getSelectedItem() == "Dirt Track")
			{
				myTrack.changeType(2);
			}
			else if (jcb3.getSelectedItem() == "Jungle")
			{
				myTrack.changeType(3);
			}
     	    		else {}
     	    
     	    }
     	 }	 
//----------------------------------------------------------------------------  
}

    public void actionPerformed(ActionEvent event) 
	    {
	
	
	       	 Object obj = event.getSource();
	       	 
	     	 if (obj == jb1)
	    	 {
			new simJFrame(myObstacle, myTrack, myCar);
	   	 	this.dispose();
			//Continue    	 
	     	 	//  Close This Window
	     	 }
	    }


    
}
