public void paintComponent(Graphics g) {
    super.paintComponent(g);

    // Dimension size = this.getSize();
    // System.out.println(size);

    Population[] populations = ga.getPopulations();
    double maxFitness = Double.NEGATIVE_INFINITY;
    double minFitness = Double.POSITIVE_INFINITY;
    double minPopNumber = Integer.MAX_VALUE;
    double maxPopNumber = Integer.MIN_VALUE;

    // Find ranges of plot.
    for (int i = 0; i < populations.length; i++) {
      Population population = populations[i];
      if (population.allIndividualsEvaluated()) {
        if (population.getMaximumFitness() > maxFitness)
          maxFitness = population.getMaximumFitness();
        if (population.getMinimumFitness() < minFitness)
          minFitness = population.getMinimumFitness();
        if (population.getPopulationNumber() > maxPopNumber)
          maxPopNumber = population.getPopulationNumber();
        if (population.getPopulationNumber() < minPopNumber)
          minPopNumber = population.getPopulationNumber();
      }
    }

    for (int i = 0; i < populations.length; i++) {
      Population population = populations[i];
      if (population.allIndividualsEvaluated()) {
        double max = population.getMaximumFitness();
        double min = population.getMinimumFitness();
        double ave = population.getAverageFitness();

        int popNumber = population.getPopulationNumber();

        g.setColor(Color.RED);
        double x = (popNumber - minPopNumber) / (maxPopNumber - minPopNumber) * getWidth();
        double y = getHeight() - (max - minFitness) / (maxFitness - minFitness) * getHeight();
        g.fillOval(((int) x), ((int) y), 4, 4);

        g.setColor(Color.BLUE);
        y = getHeight() - (ave - minFitness) / (maxFitness - minFitness) * getHeight();
        g.fillOval(((int) x), ((int) y), 4, 4);

        g.setColor(Color.BLACK);
        y = getHeight() - (min - minFitness) / (maxFitness - minFitness) * getHeight();
        g.fillOval(((int) x), ((int) y), 4, 4);
      }
    }
  }
 public void updatePanelSize() {
   sz.setSize(WIDTH, FONT_SIZE * ga.getPopulationSize());
   this.setPreferredSize(sz);
   this.updateUI();
 }