import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JSplitPane;


public class PhysicsLabApplet extends JApplet {
	 public void init()
	   {  
		  LabMenuBar menuBar=new LabMenuBar();
	      float RefreshTime = 0;
	      float DeltaTime = 0;
	      double timeWindowSize = 0;
	      String TWS = getParameter("timeWindowSize");
	      if(TWS == null){timeWindowSize = 30;}
	      else{ timeWindowSize = Double.parseDouble(TWS);}
	      
	      JPanel jl2=new JPanel();
	      Container contentPane = getContentPane();
	      BlockSpringConfiguration bsConfig = new BlockSpringConfiguration(jl2,timeWindowSize);
	      LabPanel panel = new LabPanel(bsConfig);

	      bsConfig.setLabPanel(panel);   // to repaint view when model changes 
	      InsertElementListener ieListener = new InsertElementListener(bsConfig);
	      
	      String RT = getParameter("RefreshTime");
	      String DT = getParameter("DeltaTime");
	      
	      if(RT != null && DT != null){     
	      	 RefreshTime = Float.parseFloat(RT);
	     	 DeltaTime = Float.parseFloat(DT);
	      }
	      else if(RT != null && DT == null){
	      	 RefreshTime = Float.parseFloat(RT);
	     	 DeltaTime = 0.0001f;
	      }
	      else if(RT == null && DT != null){
	      	 RefreshTime = 0.08f;
	     	 DeltaTime = Float.parseFloat(DT);
	      }
	      else {
	      	 RefreshTime = 0.08f;
	     	 DeltaTime = 0.0001f;
	      }
	      
	      Simulator sim = new Simulator(bsConfig, RefreshTime, DeltaTime); 
	      SimulatorListener sListener = new SimulatorListener(sim);
	      menuBar = new LabMenuBar(ieListener, sListener,bsConfig);
	      MouseListener mListener = new MouseListener(bsConfig, panel);
	      panel.addMouseMotionListener(mListener);
	      panel.addMouseListener(mListener);
	      
	      JSplitPane panel1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
	      panel1.add(panel); panel1.add(jl2);
	      panel.setMinimumSize(new Dimension(500,500));
	      jl2.setMinimumSize(new Dimension(200,500));
	 
	      contentPane.add(panel1);
	      setJMenuBar(menuBar);
	             
	   }
}