/*
 * All software distributed from this site Copyright The Regents of the
 * University of California and the UCSD Software Evolution Group.  All
 * Rights Reserved.
 * 
 * Permission to use, copy, modify, and distribute any part of the software
 * from this site for educational, research, and non-profit purposes,
 * without fee and without a written agreement, is hereby granted, provided
 * that the above copyright notice, this paragraph and the the following
 * three paragraphs appear in all copies.
 * 
 * For permission to use software from this site for commercial purposes,
 * contact * William G. Griswold (wgg@cs.ucsd.edu), the software's author,
 * or send U.S. Mail to:
 * 
 *         William G. Griswold
 *         Department of Computer Science and Engineering, 0114
 *         University of California, San Diego
 *         La Jolla, CA 92093-0114
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF SOFTWARE FROM THIS SITE, EVEN IF THE UNIVERSITY OF CALIFORNIA
 * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE
 * UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
 * SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.  THE UNIVERSITY OF
 * CALIFORNIA MAKES NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND,
 * EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR THAT
 * THE USE OF THE MATERIAL WILL NOT INFRINGE ANY PATENT, TRADEMARK OR OTHER
 * RIGHTS.
 */

import java.io.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Font;
import java.awt.TextArea;
import java.util.StringTokenizer;

public class BenchmarkApplet extends java.applet.Applet {

  Font courier = new Font("Courier", Font.BOLD, 14);  // For tabular formatting
  ByteArrayOutputStream bostream = new ByteArrayOutputStream();
  // WGG - in Java 1.1, PrintStream should be replaced with PrintWriter
  PrintStream pstream = new PrintStream(bostream);
  Benchmark bm = null;
  TextArea bmta = null;

public void init() {
    setFont(courier);
//    setBackground(Color.white);  // Trying to avoid color-not-found warning
    bm = new Benchmark(pstream, (getParameter("skipgc") != null), getParameter("optimization"));
    bmta = new TextArea(30, 70);
    add(bmta);
    repaint();
}

public void start() {
    while (bm.nextTest()) repaint();
}

// WGG - in Java 1.1 replaceText should be replaceRange
public void paint(Graphics g) {
    bmta.replaceText(bostream.toString(), 0, bmta.getText().length());
 }

} // end class BenchmarkApplet
