/*
* @(#)ContingencyDemo.java 0.0.0 99/07/24
*
* Copyright (c) 1999 by Willie Wheeler. All rights reserved.
*/
package stats.demos;
import java.util.*;
import javax.swing.*;
import stats.*;
/**
* This applet demonstrates the use of the ContingencyTableModel,
* and shows how it behaves in a JTable.
*
* @version 0.0.0 07/24/99
* @author Willie Wheeler
*/
public class ContingencyDemo extends JApplet {
protected JDesktopPane desktop;
protected ContingencyTableModel model;
protected int[][] states;
protected String[] stateNames;
public void init() {
ConcretePLAF.install();
desktop = new JDesktopPane();
getContentPane().add(desktop);
// Build a contingency table model.
Vector vars = new Vector();
vars.add(new TextVariable("Sex", new String[] { "Male", "Female" }));
vars.add(new TextVariable("Hair", new String[] {
"Black", "Brown", "Blond", "Red" }));
vars.add(new TextVariable("Smoker", new String[] { "Yes", "No" }));
model = new ContingencyTableModel(vars);
// Wrap the model with a JTable.
JInternalFrame tableFrame =
new JInternalFrame("Contingency Table", true, true, true, true);
tableFrame.getContentPane().add(new JScrollPane(new JTable(model)));
tableFrame.setBounds(10, 10, 300, 300);
desktop.add(tableFrame);
// Wrap the model with a BarChart.
BarChart chart = new BarChart(model, new int[] { 0, 2 });
chart.setAutoScale(false);
chart.setNumRangeGroups(10);
JInternalFrame chartFrame =
new JInternalFrame("Bar Chart", true, true, true, true);
chartFrame.getContentPane().add(new ChartWrapper(chart));
chartFrame.setBounds(320, 10, 300, 300);
desktop.add(chartFrame);
}
}