/*----------------------------------------------------------------------*/ /* SimpleApplet - a simple applet that uses Rotator */ /*----------------------------------------------------------------------*/ /* Jim Morey - morey@math.ubc.ca - May, 1996 */ /*----------------------------------------------------------------------*/ import java.io.*; import java.applet.*; import java.awt.*; import java.net.*; import java.lang.*; import Rotator; import Board; import Vertex; /*----------------------------------------------------------------------*/ public class SimpleApplet extends Applet { Rotator rotator; Checkbox rotate,black,white,empty; Button spin; URL here; int H,W,size; /* - - - - - - - - - - - - - - - - - - - - - - */ public void init() { setLayout(new BorderLayout(0,0)); setBackground(Color.white); String image = getParameter("image"); try{ size = Integer.parseInt(getParameter("size")); } catch(Exception e) { size = 3; } here = this.getDocumentBase(); Image gif=null; MediaTracker tracker; tracker = new MediaTracker(this); try { gif = getImage(new URL(here,image)); tracker.addImage(gif, 0); } catch (MalformedURLException e){ System.out.println("MalformedURLException --config!"); } catch (IOException e){ System.out.println("IOException --config!"); } /* .. get solid info .. */ W =size().width; H =size().height-40; Board board = new Board(size,W,H); try { tracker.waitForID(0); tracker.waitForID(1); } catch (InterruptedException e) { } rotator= new Rotator(this,board,W,H,gif); rotator.start(); rotator.background = new Color(255,200,200); add("Center",rotator); Panel check = new Panel(); check.add(spin = new Button("spin")); CheckboxGroup colour = new CheckboxGroup(); check.add(black = new Checkbox("black",colour,true)); check.add(white = new Checkbox("white",colour,false)); check.add(empty = new Checkbox("empty",colour,false)); add("South",check); show(); } /* - - - - - - - - - - - - - - - */ public boolean handleEvent (Event evt){ switch (evt.id){ case Event.ACTION_EVENT: if (evt.target == spin){ if (!rotator.spin){ rotator.spin = true; rotator.start(); } return true; } else if (evt.target == black){ rotator.stone=Vertex.PTR_BLACK; return true; } else if (evt.target == white){ rotator.stone=Vertex.PTR_WHITE; return true; } else if (evt.target == empty){ rotator.stone=Vertex.PTR_EMPTY; return true; } else return false; default : return false; } } /* - - - - - - - - - - - - - - - - - - - - - - */ public void stop(){ rotator.stop(); } /* - - - - - - - - - - - - - - - - - - - - - - */ public void start(){ rotator.start(); } }