import java.awt.*; import java.awt.event.MouseEvent; import java.applet.*; import java.net.*; import java.util.*; import java.io.*; import java.lang.*; import java.text.*; class OutputWindow extends Frame implements Runnable{ TextArea OutputBox = new TextArea(); Button OKButton = new Button("OK"); Button graphButton = new Button("View Graph"); Label blank1 = new Label("",Label.LEFT); private int Degree; private double x[][]; private double y[]; private double Y[], z[]; private double rms, Rsquared, MeanSquare, StandardDeviation, correlation; private int nx, Ncards, Nparms, Imethod; private boolean Constant; private StringBuf0 out; //use StringBuf0 for 1.0 compatibility; use StringBuf1 for 1.1 compatibility private reg theApplet; private Thread Printer=null; DataWindow Caller; OutputWindow(){} OutputWindow(String title, DataWindow Caller){ super(title); this.Caller = Caller; theApplet = Caller.Caller; init(); DoLayout(); //Printing in a text area could take long, so associate //a thread to that code to not interfere with parallel //interaction. if(Printer == null){ Printer = new Thread(this); Printer.start(); } } public synchronized void run(){ if(theApplet.InApplet){ theApplet.getAppletContext().showStatus("Writing output..."); } while(Printer != null){ hide(); validate(); Print(); show(); validate(); if(theApplet.InApplet){ theApplet.getAppletContext().showStatus(""); } OutputBox.requestFocus(); Printer = null; } } public final void DoLayout(){ addNotify(); resize(500, 300); OutputBox.setEditable(true); OutputBox.setFont(new Font ("Courier", Font.PLAIN, 12)); OutputBox.setBackground(Color.white); OutputBox.setForeground(Color.black); OKButton.setFont(new Font ("Arial", Font.PLAIN, 12)); OKButton.setBackground(Color.lightGray); OKButton.setForeground(Color.black); graphButton.setBackground(Color.lightGray); graphButton.setForeground(Color.black); this.setBackground(Color.magenta.darker()); this.setForeground(Color.black); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); setLayout(gridbag); //Row 1 buildConstraints(constraints, 0, 0, 1, 1, 100, 80); constraints.fill = GridBagConstraints.BOTH; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(OutputBox, constraints); add(OutputBox); //Blank card buildConstraints(constraints, 0, 1, 1, 1, 100, 5); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(blank1, constraints); add(blank1); //Row 2 buildConstraints(constraints, 0, 2, 2, 1, 100, 15); constraints.fill = GridBagConstraints.NONE; constraints.anchor = GridBagConstraints.CENTER; constraints.ipadx = 40; if( (Degree == 1) || (Imethod == 0) ){ gridbag.setConstraints(graphButton, constraints); add(graphButton); }else{ gridbag.setConstraints(OKButton, constraints); add(OKButton); } } public void buildConstraints(GridBagConstraints gbc, int gx, int gy, int gw, int gh, int wx, int wy){ gbc.gridx = gx; gbc.gridy = gy; gbc.gridwidth = gw; gbc.gridheight = gh; gbc.weightx = wx; gbc.weighty = wy; } public Insets insets(){ return new Insets(40, 15, 45, 15); } public void init() { Imethod = Caller.fit.getMethod(); Degree = Caller.fit.getDegree(); Constant = Caller.fit.isConstant(); rms = Caller.fit.getRMS(); Rsquared = Caller.fit.getRsquared(); correlation = Caller.fit.getCorrelation(); StandardDeviation = Caller.fit.getStandardDeviation(); Ncards = Caller.fit.getN(); nx = Caller.fit.getNx(); x = new double[Ncards][nx]; y = new double[Ncards]; Y = new double[Ncards]; x = Caller.fit.getX(); y = Caller.fit.getY(); Y = Caller.fit.getYY(); Nparms = Caller.fit.getNparms(); z = new double[Nparms]; z = Caller.fit.getParameters(); } public void Print(){ StringBuffer strBuf = new StringBuffer(); //Write the output to a string buffer. out = new StringBuf0(strBuf); //use StringBuf0 for 1.0 compatibility; use StringBuf1 for 1.1 compatibility out.setFieldLength(16); out.setFractionDigits(6); out.setNmax(4); // out.setForceRightPadding(true); // out.setIshift(9); // out.setFieldLspaces(10); out.setindLshift(0); PrintParameters(); PrintStats(); out.dotted_line(); //Flush the output to the text area. OutputBox.setText(strBuf.toString()); } public void PrintStats() { int i, k, Len=0; String str1=null, str2=null, str3=null; if( (Degree == 1) || (Imethod == 0) ){ out.printSpace(6); out.printSpace(1); for(i=0; i<51; i++)out.print("-"); out.printLine(); out.printSpace(3); str1 = strUtil.padString("Input X", 16); str2 = strUtil.padString("Input Y", 16); str3 = strUtil.padString("Estimated Y", 16); out.printSpace(6); out.printSpace(1); out.print(str1+str2+str3); out.printLine(); out.printSpace(6); out.printSpace(1); for(i=0; i<51; i++)out.print("-"); out.printLine(); }else{ str1 = "Input (X's, Y) and Y Estimate"; out.CenterString(str1, true); } switch(Imethod){ case 0: //Polynome Len = 3; break; case 1: //Linear Len = Degree + 2; break; default: break; } double v[] = new double[Len]; switch(Imethod){ case 0: //Polynome for(i=0; i=0; i--)b[k++] = z[i]; for(k=0, i=Degree; i>=1; i--){ str[k++] = strUtil.indexString("X^", i, 16); } str[k] = strUtil.padString("Constant", 16); if(!Constant){ b[Nparms] = 0; }else{ b[Nparms-1] = z[0]; } break; case 1: strMethod = "LINEAR"; mess2 = " of Xi"; for(k=0, i=0; i