-1

I am currently going through the example code found here: http://www.java2s.com/Code/Java/Chart/JFreeChartStackedBarChartDemo1.htm

package org.jfree.chart.demo;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;

/**
 * A simple demonstration application showing how to create a stacked bar chart
 * using data from a {@link CategoryDataset}.
 *
 */
public class StackedBarChartDemo1 extends ApplicationFrame {

    /**
     * Creates a new demo.
     *
     * @param title  the frame title.
     */
    public StackedBarChartDemo1(final String title) {

        super(title);
        final CategoryDataset dataset = createDataset();
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

    /**
     * Creates a sample dataset.
     * 
     * @return a sample dataset.
     */
    private CategoryDataset createDataset() {
        return DemoDatasetFactory.createCategoryDataset();
    }

    /**
     * Creates a sample chart.
     * 
     * @param dataset  the dataset for the chart.
     * 
     * @return a sample chart.
     */
    private JFreeChart createChart(final CategoryDataset dataset) {

        final JFreeChart chart = ChartFactory.createStackedBarChart(
            "Stacked Bar Chart Demo 1",  // chart title
            "Category",                  // domain axis label
            "Value",                     // range axis label
            dataset,                     // data
            PlotOrientation.VERTICAL,    // the plot orientation
            true,                        // legend
            true,                        // tooltips
            false                        // urls
        );
        return chart;

    }

    public static void main(final String[] args) {

        final StackedBarChartDemo1 demo = new StackedBarChartDemo1("Stacked Bar Chart Demo 1");
        demo.pack();
        RefineryUtilities.centerFrameOnScreen(demo);
        demo.setVisible(true);

    }

}

For This part

public StackedBarChartDemo1(final String title) {

        super(title);
        final CategoryDataset dataset = createDataset();
        final JFreeChart chart = createChart(dataset);
        final ChartPanel chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
        setContentPane(chartPanel);

    }

I'm a bit confused with what super(title); does. I know that it calls the parent constructor with the String parameter "tittle" but I'm hoping someone can explain what it does with the parameter. I have looked at numerous tutorials and they have helped but their answer to my question are a little to advanced for me. I understand how super() is used when calling a method from the parent class but I don't see why it is needed in this code. My guess is that it is being passed to the ApplicationFrame class to be put in the method setTitle() but I'm not sure how it works.

user3772418
  • 49
  • 1
  • 2
  • 9

1 Answers1

1

Calling super(title) will run the constructor in ApplicationFrame with the title argument. Look in ApplicationFrame to see what it is doing.

In addition, it doesn't really matter how they implement the code as long as you understand what is happening from the docs.

Dan Grahn
  • 9,044
  • 4
  • 37
  • 74
  • So it is passing the title to the constructor of ApplicationFrame? Does this mean I will have an instance of ApplicationFrame and StackedBarChartDemo1? – user3772418 Jul 15 '14 at 17:13
  • I think you need to spend some time reading about how [inheritance](http://en.wikipedia.org/wiki/Inheritance_%28object-oriented_programming%29) works. – Dan Grahn Jul 15 '14 at 17:28