To Go Back to Source Code Page, click here.
import java.applet.Applet;
import java.awt.*;
import netscape.javascript.*;  /* netscape java class--used to open a browser window */

/**
*
*      Output uses LiveConnect to output Ponzo results to another browser window
       The user can then print the results or save them to a file.  LiveConnect is only
       available on Netscape 3.0 as of the time of this writing.
       How to use this class:
          First: call method OpenBrowserWindow
          Second: call method WriteToBrowserWindow
          Third: call CloseBrowserWindow

          These method must be called in the order specified.


*
* @version Output 1.0 (C) 1997 (1/22/97)
* @author Christopher Currie
*/
public class Output {

private JSObject browserWindow;

    /**
      * This constructor requires a handle to the class that is an extention of
             an applet (the class specified by the APPLET tag in the HTML page).

      * @param a handle to applet class that is running your applet.
    */
    public Output( Applet a ){
           // get a JSObject for the window that launched the Ponzo applet
           browserWindow=JSObject.getWindow(a);

           if ( browserWindow == null )
               System.out.println("could not get browser window");
           else
                System.out.println("Browser window ok: browser window = " + browserWindow);

    }
    /**
     * OpenBrowserWindow uses the eval method, a built-in JavaScript function to open a
       browser window.
       It is not a method associated with any object, but is part of the language itself.
       The argument of the eval function is a string. Do not call eval to evaluate an arithmetic
       expression. JavaScript evaluates arithmetic expressions automatically. If the argument
       represents an expression, eval evaluates the expression. If the argument represents
       one or more JavaScript statements, eval performs the statements.

     * @param null no parameters
     * @return void
    */
    public void OpenBrowserWindow(){
           // The open method opens a new web browser window on the client, similar to choosing
           // New Web Browser from the File menu of the Navigator. The URL argument specifies
           // the URL contained by the new window. If URL is an empty string, a new, empty
           // window is created.
           // [windowVar = ][window].open("URL", "windowName", ["windowFeatures"])
           browserWindow.eval("myWindow = window.open('','displayWindow')");

           // Open a stream to collect the output of write or writeln methods.
           // Syntax
           //        document.open(["mimeType"])
           //
           // mimeType specifies any of the following document types:
           //
           //  text/html - specifies a document containing ASCII text with HTML formatting.
           //  text/plain - specifies a document containing plain ASCII text with end-of-line
           //               characters to delimit displayed lines.
           //  image/gif
           //  image/jpeg
           //  image/x-bitmap
           //  plugIn
           browserWindow.eval("myWindow.document.open('text/html')");
    }

    /**
      * if you don't call myWindow.document.close(),the user will
        not be able to print or save the document you wrote.

      * @param null no parameters
      * @return void
    */
    public void CloseBrowserWindow(){
           browserWindow.eval("myWindow.document.close()");
    }

    /**
      * This method sends text/html commands to the document (i.e., the browser window).
             For other applets, the parameter list and text to browser window will be different. 

      * @param asc holds individual ascending trial data: lower & upper threshold & PSE
      * @param meanLTAsc holds average lower threshold for ascending type of data.
      * @param meanUTAsc holds average upper threshold for ascending type of data.
      * @param meanPSEAsc average point of subjective equality for ascending type of data.
      * @param dec holds individual decending trial data: lower & upper threshold & PSE
      * @param meanLTDec holds average lower threshold for decending type of data.
      * @param meanUTDec holds average upper threshold for decending type of data.
      * @param meanPSEDec average point of subjective equality for decending type of data.
      * @param meanLT lower threshold for all trials.
      * @param meanUT upper threshold for all trials.
      * @param meanPSE point of subjective equality for all trials.
      * @return void
    */
    public void WriteToBrowserWindow(double asc[][], double meanLTAsc, double meanUTAsc, double meanPSEAsc,
                                     double dec[][], double meanLTDec, double meanUTDec, double meanPSEDec,
                                     double meanLT, double meanUT, double meanPSE, int n){

      // prelim html
         WriteDoc("");
         //  ... 
         WriteDoc("PONZO RESULTS: PRINT AND/OR SAVE WINDOW");
         // what this window is and instructions
         WriteDoc("

PONZO RESULTS
PRINT AND/OR SAVE WINDOW

"); WriteDoc("To print or save this window, use the File menu, print or save button
"); // DATA WriteDoc("


"); WriteDoc("

Trial   Trial      Lower      Upper      Point of subjective
number type threshold threshold equality
"); for ( int i = 0; i < n; i++ ){ WriteDoc("
");WriteDoc(Integer.toString((int)asc[i][3]));WriteDoc("    ");
             if ( asc[i][3] > 9 )
                 WriteDoc("  Ascending    ");
             else
                 WriteDoc("   Ascending    ");
             WriteDoc(Double.toString(asc[i][0]));WriteDoc("%        ");
             WriteDoc(Double.toString(asc[i][1]));WriteDoc("%        ");
             WriteDoc(Double.toString(asc[i][2]));WriteDoc("%
"); } for ( int i = 0; i < n; i++ ){ WriteDoc("
");WriteDoc(Integer.toString((int)dec[i][3]));WriteDoc("    ");
             if ( dec[i][3] > 9 )
                 WriteDoc("  Decending    ");
             else
                 WriteDoc("   Decending    ");
             WriteDoc(Double.toString(dec[i][0]));WriteDoc("%       ");
             WriteDoc(Double.toString(dec[i][1]));WriteDoc("%       ");
             WriteDoc(Double.toString(dec[i][2]));WriteDoc("%
"); } WriteDoc("
Mean lower threshold for ASCENDING trials:          ");WriteDoc(Double.toString(meanLTAsc));WriteDoc("
"); WriteDoc("Mean upper threshold for ASCENDING trials: ");WriteDoc(Double.toString(meanUTAsc));WriteDoc("
"); WriteDoc("Point of subjective equality for ASCENDING trials: ");WriteDoc(Double.toString(meanPSEAsc));WriteDoc("
"); WriteDoc("
Mean lower threshold for DECENDING trials:          ");WriteDoc(Double.toString(meanLTDec));WriteDoc("
"); WriteDoc("Mean upper threshold for DECENDING trials: ");WriteDoc(Double.toString(meanUTDec));WriteDoc("
"); WriteDoc("Point of subjective equality for DECENDING trials: ");WriteDoc(Double.toString(meanPSEDec));WriteDoc("
"); WriteDoc("
Lower threshold for ALL trials               :");WriteDoc(Double.toString(meanLT));WriteDoc("
"); WriteDoc("
Upper threshold for ALL trials               :");WriteDoc(Double.toString(meanUT));WriteDoc("
"); WriteDoc("
Point of subjective equality for ALL trials  :");WriteDoc(Double.toString(meanPSE));WriteDoc("
"); // ending html stuff WriteDoc(""); WriteDoc(""); } /** * Use this private method to write data (formated as strings) and HTML commands to the opened document (i.e., browser window). * @param s data or HTML commands. * @return void */ private void WriteDoc(String s) { browserWindow.eval("myWindow.document.write('"+s+"')"); } }