/* TextPlotApplet base class used for applet versions of Kernighan and Wyk's Java Timing tests. @Author: Christopher Hylands, based on Prime.java by Tom Parks @Version:@(#)TextPlotApplet.java 1.2 02/05/98 @Copyright (c) 1998 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. 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 THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ import java.applet.Applet; import java.awt.*; import java.net.*; // Need URL import ptplot.*; ////////////////////////////////////////////////////////////////////////// //// TextPlotApplet /** * Base class used for applet versions of Kernighan and Wyk's Java timing * tests. * This applet brings up a TextArea and a Ptplot. */ public class TextPlotApplet extends Applet implements Runnable { /** * Handle button presses. * @deprecated As of JDK1.1 in java.awt.component * but we need to compile under 1.0.2 for netscape3.x compatibility. */ public boolean action (Event evt, Object arg) { if (evt.target == _startButton) { runTest(); return true; } else { return super.action (evt, arg); // action() is deprecated in 1.1 // but we need to compile under // jdk1.0.2 for netscape3.x } } /** Return a string describing this applet. */ public String getAppletInfo() { return "TextPlotApplet: Applet interface to Kernighan & Wyk's " + "timing tests\n" + "By: Christopher Hylands, cxh@eecs.berkeley.edu\n" + "@(#)TextPlotApplet.java 1.2 02/05/98"; } /** Return the name of the Frame. */ public Frame getFrame() { Component parent = this; do { parent = parent.getParent(); } while (! (parent instanceof Frame)); return (Frame) parent; } /** Return information about parameters. */ public String[][] getParameterInfo () { String pinfo[][] = { {"background", "hexcolor value", "background color"}, {"foreground", "hexcolor value", "foreground color"}, }; return pinfo; } /** * Initialize the applet. Read the applet parameters. */ public void init() { int width, height; setLayout(new BorderLayout()); output = new TextArea(16,16); output.setEditable(false); // Process the width and height applet parameters try { width = Integer.valueOf(getParameter("width")).intValue(); } catch (NullPointerException e) { width = 400; } try { height = Integer.valueOf(getParameter("height")).intValue(); } catch (NullPointerException e) { height = 400; } if (_debug > 8) System.out.println("TextPlotApplet: init: about to resize"+width); resize(width,height); // Process the background parameter. try { Color background = Color.white; try { // Check to see if it is a hexadecimal // Can't use Color decode here, it is not in 1.0.2 //Color col = Color.decode(name); background = new Color(Integer.parseInt(getParameter("background"),16)); } catch (NumberFormatException e) { System.out.println("Failed to parse "+getParameter("background") + e); } System.out.println("Background: "+background); setBackground(background); } catch (NullPointerException e) {} // Process the foreground parameter. try { Color foreground = Color.black; try { // Check to see if it is a hexadecimal // Can't use Color decode here, it is not in 1.0.2 //Color col = Color.decode(name); foreground = new Color(Integer.parseInt(getParameter("foreground"),16)); } catch (NumberFormatException e) {} setForeground(foreground); } catch (NullPointerException e) {} add("West", output); add("Center",timeplot); Panel panel = new Panel(); panel.setLayout(new FlowLayout(FlowLayout.LEFT)); Label loopLabel = new Label("Number of Java Iterations"); panel.add(loopLabel); _loopField = new TextField("10",6); panel.add(_loopField); _startButton = new Button("Start tests under Java"); panel.add( _startButton); _frame = getFrame(); add("South", panel); show(); timeplot.init(); super.init(); } /** Paint the screen. */ public void paint(Graphics graphics) { if (_debug > 8) System.out.println("TextPlotApplet: paint"); } public void run () { if (_debug > 8) System.out.println("TextPlotApplet: run"); } /** * The runTest() method should be overridden in the * child classes. runTest() should parse _loopField and * then call runOneTest(). */ public void runTest () { _frame.setCursor(Frame.WAIT_CURSOR); output.appendText("Child classes should have their own"+ " runTest() method, which calls runOneTest"); int loops = 0; try { loops = Integer.parseInt(_loopField.getText()); } catch (NumberFormatException e) {} output.appendText("loop: "+loops); runOneTest(loops, 125000); //runOneTest(loops, 250000); //runOneTest(loops, 500000); //runOneTest(loops, 1000000); _frame.setCursor(Frame.DEFAULT_CURSOR); } /** * The runOneTest() method should be overridden in the * child classes. runOneTest() should call whatever code * that actually runs the test. */ public void runOneTest (int loops, int n) { output.appendText("Child classes should have their own"+ " runOneTest(loops, n) method"); } /** Start the applet. */ public void start () { if (_debug > 8) System.out.println("TextPlotApplet: start"); _TextPlotAppletThread = new Thread(this); _TextPlotAppletThread.start(); super.start(); } /** Stop the applet. */ public void stop () { if (_debug > 8) System.out.println("TextPlotApplet: stop"); _TextPlotAppletThread.stop(); } ////////////////////////////////////////////////////////////////////////// //// public variables //// // This is public so we can access it from JavaScript. public Plot timeplot; public TextArea output; ////////////////////////////////////////////////////////////////////////// //// protected variables //// protected Frame _frame; protected TextField _loopField; protected Button _startButton; // If non-zero, print out debugging messages. protected int _debug = 0; ////////////////////////////////////////////////////////////////////////// //// private variables //// // Thread for this applet. private Thread _TextPlotAppletThread; }