/* * @(#)SamplerDemo.java 0.0.0 99/07/07 * * Copyright (c) 1999 by Willie Wheeler. All rights reserved. */ package stats.demos; import java.io.*; import java.awt.*; import javax.swing.*; import javax.swing.table.*; import stats.*; /** * Demonstrates the use of the Sampler classes. The filter * architecture for this demo is as follows: *
 *     BallSampler (generates color data)
 *       |
 *     Tabulator (tabulates colors)
 *       |
 *       |____BarChart (charts distribution of colors for current sample)
 *       |
 *       |____Collector (collects the rel freqs of red over multiple samples)
 *              |
 *            NumericGrouper (groups the rel freqs)
 *              |
 *            Tabulator (tabulates rel freq groups)
 *              |
 *            BarChart (charts distribution of rel freq groups)
 * 
* * BUGS: If an "ungrouped" datum comes up (and this is possible), * then a NumberFormatException is thrown and the applet does not * work any longer. * * @version 0.0.0 07/07/99 * @author Willie Wheeler */ public class SamplerDemo extends JApplet { protected BallSampler sampler; protected Tabulator tab1, tab2; protected BarChart chart1, chart2; protected Collector collector; protected NumericGrouper grouper; public void init() { // Install the concrete plaf. ConcretePLAF.install(); // Build and add a desktop pane. JDesktopPane desktop = new JDesktopPane(); setContentPane(desktop); // Temp frame var. JInternalFrame frame; // Build and frame a sampler. System.err.println("Building sampler..."); sampler = new BallSampler(new int[] { 1000, 200, 300, 500, 500 }); frame = new JInternalFrame("Sampler", true, true, true, true); frame.setBounds(10, 10, 240, 240); frame.getContentPane().add(new SamplerWrapper(sampler)); desktop.add(frame); // Build a tabulator. System.err.println("Building tab1..."); tab1 = new Tabulator(sampler.getDataOut(), BallSampler.COLOR_COLUMN); // Build and frame a bar chart. System.err.println("Building chart1..."); chart1 = new BarChart(tab1.getDataOut(), Tabulator.CAT_COL, Tabulator.FREQ_COL, sampler.getCategoryColors()); frame = new JInternalFrame("Bar Chart", true, true, true, true); frame.setBounds(260, 10, 240, 240); frame.getContentPane().add(new ChartWrapper(chart1)); desktop.add(frame); // Build a collector. 0 here is the row index for color = red. System.err.println("Building collector..."); collector = new Collector(tab1.getDataOut(), 0, Tabulator.REL_FREQ_COL); // Build a grouper. 0 here is the column index for color = red. System.err.println("Building grouper..."); grouper = new NumericGrouper(collector.getDataOut(), 0, 0.3, 0.5, 10); // Build another tabulator. System.err.println("Building tab2..."); tab2 = new Tabulator(grouper.getDataOut(), NumericGrouper.GROUP_COLUMN); // Build and frame another bar chart. System.err.println("Building chart2..."); chart2 = new BarChart(tab2.getDataOut(), Tabulator.CAT_COL, Tabulator.FREQ_COL); chart2.setAutoScale(true); chart2.setNumRangeGroups(20); frame = new JInternalFrame("Bar Chart", true, true, true, true); frame.setBounds(10, 260, 490, 340); frame.getContentPane().add(new ChartWrapper(chart2)); desktop.add(frame); } }