import java.awt.*; import java.applet.Applet; import java.util.*; import ca.*; public class RandomCAs extends Applet { CAs animator; String cas[]; Thread th; int max; boolean wrap = true; /** *情報 */ public String getAppletInfo() { return "RandomCAs v0.2 (09 Oct 1996),by task gouda"; } /** *パラメーターの説明 */ public String[][] getParameterInfo() { String pinfo[][] = { {"max", "int", "the number of CAs"}, {"CAs", "String", "CA list exanple(\"ca.Life,ca.Brain,ca.Vote,ca.Rug,ca.Faders\")"}, {"Wrap", "boolean", "true/false World Edge mode"}, }; return pinfo; } public void init() { Dimension r = size(); resize( r.width , r.height ); Graphics g = getGraphics(); g.setColor(Color.black); g.fillRect(0,0,r.width,r.height); max = getParamNum("max"); String txt = getParameter("Wrap"); if ( txt != null ){ wrap = (Boolean.valueOf(txt)).booleanValue(); } String name = getParameter("CAs"); if ( name != null ){ cas = new String[max]; StringTokenizer st = new StringTokenizer(name,",",false); for(int i = 0 ; i < max;i++){ try{ cas[i] = st.nextToken(); }catch( NoSuchElementException e ){ max = i+1; break; } } }else{ max = 0; } } //get parameterNumber. public int getParamNum(String st) { int num=0; String title=getParameter(st); if(st!=null) num=Integer.valueOf(title).intValue(); //else System.out.println(st+" is null"); return num; } public void start(){ if ( th == null ){ try{ int x = (int)(Math.random()*max); if (x<0){ x=0; }else if (x>=max){ x=max-1; } animator = (CAs)((Class.forName(cas[x])).newInstance()); animator.setTarget(this); animator.setWrap(wrap); th = new Thread(animator); th.start(); } catch (ClassNotFoundException e ){ System.out.println("-- Class Not Found! --"); }catch (Exception e){ System.out.println("-- Error: -- " + e); } //animator = new Life(this); //animator.start(); } } public void stop(){ if ( (th != null) && th.isAlive() ){ th.stop(); } th = null; System.runFinalization(); System.gc(); } public void destroy(){ this.stop(); } public void update(Graphics g){ paint(g); } public void paint( Graphics g ) { //g.drawImage(bufimg,0,0,this); } public boolean mouseUp (Event e ,int x , int y){ this.stop(); this.start(); return true; } public static void main(String args[]) { //com.metrowerks.AppletFrame.startApplet("LifeTest", "Life Test", args); } }