//****************************************************************************** // GeneticAlgorithms.java: Applet // //****************************************************************************** import java.applet.*; import java.awt.*; import RunInformationDialog; import Executor; import Individual; import BooleanIndividual; //============================================================================== // Main Class for applet GeneticAlgorithms // //============================================================================== public class GeneticAlgorithms extends Applet { // STANDALONE APPLICATION SUPPORT: // m_fStandAlone will be set to true if applet is run standalone //-------------------------------------------------------------------------- Button theButton; boolean m_fStandAlone = false; // STANDALONE APPLICATION SUPPORT // The main() method acts as the applet's entry point when it is run // as a standalone application. It is ignored if the applet is run from // within an HTML page. //-------------------------------------------------------------------------- public GeneticAlgorithms() { // TODO: Add constructor code here } public static void main(String args[]) { GeneticAlgorithms applet = new GeneticAlgorithms(); applet.m_fStandAlone=true; applet.spawn(); } // GeneticAlgorithms Class Constructor //-------------------------------------------------------------------------- // APPLET INFO SUPPORT: // The getAppletInfo() method returns a string describing the applet's // author, copyright date, or miscellaneous information. //-------------------------------------------------------------------------- public String getAppletInfo() { return "Genetic Algorithms in Java\r\n" + "Authors: Thinkquest Team 29483\r\n" + "Primary Author: Douglas Quentin Hawkins"; } // The init() method is called by the AWT when an applet is first loaded or // reloaded. Override this method to perform whatever initialization your // applet needs, such as initializing data structures, loading images or // fonts, creating frame windows, setting the layout manager, or adding UI // components. //-------------------------------------------------------------------------- public void init() { theButton=new Button("View Genetic Algorithms"); this.setLayout(new BorderLayout(0,0)); this.add("Center", theButton); this.resize(100,25); this.show(); // TODO: Place additional initialization code here } // Place additional applet clean up code here. destroy() is called when // when you applet is terminating and being unloaded. //------------------------------------------------------------------------- public void destroy() { // TODO: Place applet cleanup code here } // GeneticAlgorithms Paint Handler //-------------------------------------------------------------------------- public boolean action(Event evt, Object arg) { if (evt.target==theButton) { spawn(); return true; } return false; } static final String PARAM_Individual="Individual"; public Individual getIndividual() throws ClassNotFoundException, InstantiationException, IllegalAccessException { String indivClass = getParameter(PARAM_Individual); Individual baseIndividual; if (indivClass==""||indivClass==null) baseIndividual = new BooleanIndividual(); else baseIndividual = (Individual) Class.forName(indivClass).newInstance(); return baseIndividual; } public void spawn() { try { Individual base=getIndividual(); String individualClass = getParameter(PARAM_Individual); System.out.println("Ran spawn()"); RunInformationDialog dialog = new RunInformationDialog( new Executor(new GenerationsGenerator( 100, new BooleanIndividual(), (float)0.9,(float)0.0001 ) ) ); dialog.show(); } catch (Exception e) { System.err.println(e); theButton.setLabel("Error can load "+getParameter(PARAM_Individual)); } } public void paint(Graphics g) { // TODO: Place applet paint code here } }