I have created a rather complex graph that updates dynamically during runtime as per the code snippet below.
within Main
Code: Select all
if(singleRun){
try{
FileInputStream fin = new FileInputStream("C:\\eclipse\\data\\so.gad");
ObjectInputStream ois = new ObjectInputStream(fin);
SO = (GAStatisticObject) ois.readObject();
ois.close();
}
catch(FileNotFoundException FNFE){System.out.println("file not found"); System.exit(1);}
catch(ClassNotFoundException CNFE){System.out.println("class not found");System.exit(1);}
catch(IOException IOE){System.out.println("error during data save: "); IOE.printStackTrace();System.exit(1);}
GenotypeSimulator GS = new GenotypeSimulator(SO, populationSize); //statistic object, population size, enable immediately
GS.simulateEvolution();
}
create a new simulation engine (GenotypeSimulator), which in turn creates and instantiates the GUI and charts.
and then start the simulation which basically reads the data file one data point at a time and updates the graphs. (code for simulator is below)
Code: Select all
//only used for live execution monitoring
public void simulateEvolution(){
for(int x=0; x<genNumberSolutionFound; x++){
//System.out.println("updating data. GEN # = " + (x+1));
try {Thread.sleep(1000);}
catch (InterruptedException e) {e.printStackTrace();}
//data series 1
XYDataItem point1 = null;
if(x<genNumberSolutionFound-1){//parent vector is always 1 less in length then the rest
point1 = new XYDataItem(new Double(x+1), new Double(selectedFitnessAvg.get(x))); //parent select avg fitness
}
XYDataItem point2 = new XYDataItem(new Double(x+1), new Double(populationFitnessAvg.get(x))); //avg fitness
XYDataItem point3 = new XYDataItem(new Double(x+1), new Double(populationSmallestFitness.get(x))); //low fitness
XYDataItem point4 = new XYDataItem(new Double(x+1), new Double(populationLargestFitness.get(x))); //high fitness
//data series 2
XYDataItem point5 = new XYDataItem(new Double(x+1), new Double(cumulativeAllelDistributionVector.get(x))); //diversity
Vector<XYDataItem> DI = new Vector<XYDataItem>();
DI.add(point1); //parent avg fitness
DI.add(point2); //avg fitness
DI.add(point3); //low fitness
DI.add(point4); //high fitness
DI.add(point5); //average diversity
LGP.updateAllDataSeries(DI, new Integer(sizeOfPopulation*(x+1)));
BGP.updateDataSet(x+1, instantaneousAllelDistributionMatrix.get(x));
}
BGP.setGARunComplete();
}
THIS WORKS GREAT! as can be seen from the picture below. all my lineseries and bargraphs update perfectly.

now here is where the problem comes in. What I really want to do is start the simulation from another JFrame when I click on a JButton; instead of from my main function directly. So I created a new "execution control panel" (top left in the figure below) and when you click on the start button, it executes exactly the same code previously displayed within its event handler (read object, create simulator, and then start the simulation).
however, as you can see from the figure, all I get is a window that is mostly blank and no longer updates dynamically like before. I know the simulation is running fine because I still see the println statements to StdOut, but the GUI remains blank until the "evolveSolution()" method completes and then updates all at once.

anyone have any idea why I am getting this different behavior when executing from another GUI?
thanks. this one really has me stumped.