import java.awt.*;
import javax.swing.*;
import simulate.Simulation2D;
import simulate.DisplayConfiguration;
import simulate.Phase;
import simulate.SpeciesDisks;
import simulate.P2LennardJones;
import simulate.ControllerButton;
import simulate.IntegratorVerlet;

/**
 * A basic extension of the javax.swing.JApplet class
 */
public class VerletLJ extends JApplet
{
	public void init()
	{
		// Take out this line if you don't use symantec.itools.net.RelativeURL or symantec.itools.awt.util.StatusScroller
		symantec.itools.lang.Context.setApplet(this);
		
		// This line prevents the "Swing: checked access to system event queue" message seen in some browsers.
		getRootPane().putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE);
		
		// This code is automatically generated by Visual Cafe when you add
		// components to the visual environment. It instantiates and initializes
		// the components. To modify the code, only use code syntax that matches
		// what Visual Cafe can generate, or Visual Cafe may be unable to back
		// parse your Java file into its visual environment.
		//{{INIT_CONTROLS
		getContentPane().setLayout(null);
		getContentPane().setBackground(java.awt.Color.white);
		setSize(570,383);
		simulation2D1.setLayout(null);
		getContentPane().add(simulation2D1);
		simulation2D1.setBounds(24,24,400,300);
		displayConfiguration1.setLayout(null);
		simulation2D1.add(displayConfiguration1);
		displayConfiguration1.setBounds(96,0,300,300);
		phase1.setLayout(null);
		simulation2D1.add(phase1);
		phase1.setBounds(24,204,20,40);
		speciesDisks1.setLayout(null);
		simulation2D1.add(speciesDisks1);
		speciesDisks1.setBounds(60,228,20,40);
		simulation2D1.add(P2LennardJones1);
		P2LennardJones1.setBounds(12,156,60,60);
		controllerButton1.setLayout(null);
		simulation2D1.add(controllerButton1);
		controllerButton1.setBounds(0,48,100,40);
		integratorVerlet1.setDoSleep(false);
		integratorVerlet1.setDrawTimeStep(0.00015);
		integratorVerlet1.setLayout(null);
		controllerButton1.add(integratorVerlet1);
		integratorVerlet1.setBounds(60,0,20,40);
		JSlider1.setMinimum(2);
		JSlider1.setMinorTickSpacing(1);
		JSlider1.setValue(20);
		JSlider1.setMaximum(50);
		JSlider1.setPaintLabels(true);
		JSlider1.setToolTipText("Number of atoms");
		JSlider1.setPaintTicks(true);
		getContentPane().add(JSlider1);
		JSlider1.setBounds(120,324,300,40);
		//}}
	
		//{{REGISTER_LISTENERS
		SymChange lSymChange = new SymChange();
		JSlider1.addChangeListener(lSymChange);
		//}}
	}

	//{{DECLARE_CONTROLS
	simulate.Simulation2D simulation2D1 = new simulate.Simulation2D();
	simulate.DisplayConfiguration displayConfiguration1 = new simulate.DisplayConfiguration();
	simulate.Phase phase1 = new simulate.Phase();
	simulate.SpeciesDisks speciesDisks1 = new simulate.SpeciesDisks();
	simulate.P2LennardJones P2LennardJones1 = new simulate.P2LennardJones();
	simulate.ControllerButton controllerButton1 = new simulate.ControllerButton();
	simulate.IntegratorVerlet integratorVerlet1 = new simulate.IntegratorVerlet();
	javax.swing.JSlider JSlider1 = new javax.swing.JSlider();
	//}}

	class SymChange implements javax.swing.event.ChangeListener
	{
		public void stateChanged(javax.swing.event.ChangeEvent event)
		{
			Object object = event.getSource();
			if (object == JSlider1)
				JSlider1_stateChanged(event);
		}
	}

	void JSlider1_stateChanged(javax.swing.event.ChangeEvent event)
	{
		// to do: code goes here.
		controllerButton1.clickForPause();	 
		JSlider1_stateChanged_Interaction1(event);
		integratorVerlet1.initialize();
		displayConfiguration1.repaint();
	}

	void JSlider1_stateChanged_Interaction1(javax.swing.event.ChangeEvent event)
	{
		try {
			// JSlider1 Get the JSlider's current value
			speciesDisks1.setNMolecules(JSlider1.getValue());
		} catch (java.lang.Exception e) {
		}
	}
}
