import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.text.*; public class Auto extends Applet implements ActionListener { TextField theText[] = new TextField[6]; TextArea theArea; Button theButton; public void init() { Panel thePanel = new Panel(); Panel thePanel2 = new Panel(); Panel thePanel3 = new Panel(); Panel thePanel4 = new Panel(); setLayout(new GridLayout(5, 1)); setFont(new Font("Tahoma", Font.BOLD, 15)); theArea = new TextArea("Enter the list of random numbers here"); theArea.setBackground(Color.green); thePanel.setBackground(Color.magenta); thePanel.setFont(new Font("Tahoma", Font.BOLD, 15)); thePanel2.setBackground(Color.cyan); thePanel.setFont(new Font("Tahoma", Font.BOLD, 15)); thePanel4.setBackground(Color.orange); Label theLabels[] = new Label[10]; setBackground(Color.white); theButton = new Button("Process"); thePanel3.add(theButton); theLabels[0] = new Label("M: "); theLabels[1] = new Label("m: "); theLabels[2] = new Label("i: "); theLabels[3] = new Label("N: "); theLabels[4] = new Label("Pim: "); theLabels[5] = new Label("Qpim: "); theLabels[6] = new Label("Zo: "); theLabels[0].setFont(new Font("Tahoma", Font.BOLD, 18)); theLabels[1].setFont(new Font("Tahoma", Font.BOLD, 18)); theLabels[2].setFont(new Font("Tahoma", Font.BOLD, 18)); theLabels[3].setFont(new Font("Tahoma", Font.BOLD, 18)); theLabels[4].setFont(new Font("Tahoma", Font.BOLD, 18)); theLabels[5].setFont(new Font("Tahoma", Font.BOLD, 18)); theText[0] = new TextField(5); theText[1] = new TextField(5); theText[2] = new TextField(5); theText[3] = new TextField(5); theText[4] = new TextField(5); theText[5] = new TextField(5); theText[4].setEditable(false); theText[5].setEditable(false); theText[0].setEditable(false); theText[3].setEditable(false); thePanel.add(theLabels[1]); thePanel.add(theText[1]); thePanel.add(theLabels[2]); thePanel.add(theText[2]); thePanel2.add(theLabels[0]); thePanel2.add(theText[0]); thePanel2.add(theLabels[3]); thePanel2.add(theText[3]); thePanel4.add(theLabels[4]); thePanel4.add(theText[4]); thePanel4.add(theLabels[5]); thePanel4.add(theText[5]); theButton.addActionListener(this); add(thePanel); add(thePanel2); add(thePanel4); add(theArea); add(thePanel3); } public void actionPerformed(ActionEvent e) { StringTokenizer theTokens; String temp=""; int lag=0, index=0; int temp1=0, temp2=0, M=0; int tokes=0, counter=0; Vector theVec = new Vector(); double Qpim=0, Pim=0, r1=0, r2=0, store=0; DecimalFormat format[] = new DecimalFormat[3]; format[0] = new DecimalFormat("##0.0###"); format[1] = new DecimalFormat("##0.0###"); format[2] = new DecimalFormat("##0.0###"); //get all the data try{ lag = Integer.parseInt(theText[1].getText()); index = Integer.parseInt(theText[2].getText()); System.out.println("lag "+lag+" "+" index "+index); }catch(NumberFormatException nfe){ theArea.setText("Error information: You did not enter all numeric values.\nPush refresh in the browser and try again."); }catch(Exception exe){ theArea.setText("Error information: An unknown error has occured.\nPush refresh in the browser and try again."); } //tokenize theTokens = new StringTokenizer(theArea.getText()); double values[] = new double[theTokens.countTokens()]; try{ while(theTokens.hasMoreTokens()) { temp = theTokens.nextToken(); values[tokes++] = Double.parseDouble(temp); } }catch(Exception ede){ theArea.setText("Error information: An unknown error has occured.\nPush refresh in the browser and try again."); } r1 = values[index-1]; for(counter=index-1;(counter+lag) < values.length; ) { r2 = r1; counter += lag; r1 = values[counter]; store += r2 * r1; } System.out.println(store); //calculate M temp1 = lag + index; temp2 = tokes - temp1; M = (int)temp2/lag; //calculate Qpim Qpim = Math.sqrt((13*M+7)) / (12*(M+1)); //caclulate Pim Pim = ((1.0/(((double)M)+1.0)) * store) - 0.25; //set values theText[3].setText(""+tokes); theText[0].setText(""+M); theText[5].setText(""+format[0].format(Qpim)); theText[4].setText(""+format[1].format(Pim)); String type; if(Pim < 0) type = "Negative Correlation: "; else type = "Positive Correlation: "; double zVal = (Pim/Qpim); String pass; if(1.96 >= zVal && -1.96 <= zVal) pass = "This passes a two-tailed test with an alpha value of 0.05."; else pass = "This fails a two-tailed test with an alpha value of 0.05."; theArea.setText("Important information: "+ type +""+ format[2].format(zVal)+"\n"+pass); } }