import java.awt.*;

public class Ising extends java.applet.Applet {

// Control applet for Ising model simulation

// Four objects needed - 2 components on screen - a drawing surface and
// a user control panel , 1 simulation object and 1 thread
// to control the latter.


public DrawSpins drawing;
public IsingSimulation simulation;
public Controls usercontrols;
public Thread runner;

private int appletwidth,appletheight;
public int L=8,spin_spacing,circle_size,iborder,jborder;


public void init(){

// compute size of spins in drawing surface and resize

// following works fine in appletviewer but not in netscape 
// no idea why not

//spin_spacing = size().width/L;
//circle_size = (int) (0.75*spin_spacing);
//appletwidth = spin_spacing*(L+3);
//appletheight = (int) (1.15*appletwidth);
//resize(appletwidth,appletheight);

// so hard code sizes here

  spin_spacing = 24;
  circle_size = 18;
  iborder = 72; 
  jborder = 48;

// set layout of components, create the latter and add them

setLayout(new BorderLayout());
usercontrols = new Controls(this);
drawing = new DrawSpins(this);

add("Center",drawing);
add("South",usercontrols);

}


public void start(){
// create instance of our simulation

simulation = new IsingSimulation(this);

// attach a thread to it

if(runner == null){
runner = new Thread(simulation);
runner.start();}
}

public void stop(){
// stop thread (and hence simulation) if exit off page

if(runner!=null){
runner.stop();
runner=null;}
}


}

