/*********************************************************************/ /*** ***/ /*** Program Name: fin2.java ***/ /*** Programmer: Wendy S. Mechler ***/ /*** Date: May 5, 1996 ***/ /*** Modified to work by Roger Webster, Ph.D 11/2000 ***/ /*** Purpose: This Java applet will present a graphiccal user ***/ /*** interface which will allow the user to choose ***/ /*** a type of chart to be graphed, enter title, x ***/ /*** and y axis labels and units, and points. With ***/ /*** this information the appropriate chart will be ***/ /*** graphed. ***/ /*** ***/ /*********************************************************************/ /*** ***/ /*** All files for this applet and pages going with this applet ***/ /*** can be found at: cs.millersv.edu/~wsmechle/final/ ***/ /*** There are two html files: final1.html and final2.html ***/ /*** bring up final1.html first. ***/ /*** To run the applet click on the "Run Chart Graphing Applet" ***/ /*** button. ***/ /*** - Choose a type of graph ***/ /*** - Enter title, labels and units ***/ /*** - Enter x and y values ***/ /*** - Choose the number of points ***/ /*** - Click the "Graph it " button ***/ /*** - to quit click the "Quit button" ***/ /*** ***/ /*** Test Data: ***/ /*** Pareto Diagram: ***/ /*** Title: Data Package Avg. TAT x | y ***/ /*** x Label: Employee ----------- ***/ /*** y Label: TAT Sue | 3 ***/ /*** x units: Jean| 5 ***/ /*** y units: Days Bill| 4 ***/ /*** # of pts: 5 Karen| 2 ***/ /*** Bob | 3 ***/ /*** ***/ /*** Histogram: ***/ /*** Title: CS161 Final x | y ***/ /*** x Label: Test Score ----------- ***/ /*** y Label: Total 100 | 1 ***/ /*** x units: Percent 95 | 3 ***/ /*** y units: 90 | 5 ***/ /*** # of pts: 11 85 | 7 ***/ /*** 80 | 8 ***/ /*** 75 | 6 ***/ /*** 70 | 4 ***/ /*** 65 | 4 ***/ /*** 60 | 2 ***/ /*** 55 | 1 ***/ /*** 35 | 1 ***/ /*** ***/ /*** Correlation Chart: ***/ /*** Title: Effect of DF on Result x | y ***/ /*** x Label: Dilution Factor ----------- ***/ /*** y Label: Result 1 | 3 ***/ /*** x units: ug 5 | 17 ***/ /*** y units: ug 10 | 26 ***/ /*** # of pts: 7 25 | 71 ***/ /*** 50 | 158 ***/ /*** 100 | 280 ***/ /*** 150 | 462 ***/ /*** ***/ /*** Run Chart: ***/ /*** Title: Sales for 1996 x | y ***/ /*** x Label: Month ----------- ***/ /*** y Label: Total sales 1 | 100 ***/ /*** x units: 2 | 83 ***/ /*** y units: $K 3 | 112 ***/ /*** # of pts: 12 4 | 127 ***/ /*** 5 | 197 ***/ /*** 6 | 233 ***/ /*** 7 | 258 ***/ /*** 8 | 261 ***/ /*** 9 | 231 ***/ /*** 10 | 183 ***/ /*** 11 | 110 ***/ /*** 12 | 76 ***/ /*** ***/ /*** Control Chart: ***/ /*** Title: TAT for 1996 x | y ***/ /*** x Label: Month ----------- ***/ /*** y Label: TAT 1 | 14 ***/ /*** x units: 2 | 15 ***/ /*** y units: Days 3 | 17 ***/ /*** # of pts: 12 4 | 19 ***/ /*** 5 | 17 ***/ /*** 6 | 25 ***/ /*** 7 | 18 ***/ /*** 8 | 16 ***/ /*** 9 | 13 ***/ /*** 10 | 15 ***/ /*** 11 | 14 ***/ /*** 12 | 15 ***/ /*** ***/ /*********************************************************************/ import java.applet.*; import java.awt.*; import java.net.*; import java.lang.*; import java.lang.Math; import java.awt.event.*; public class fin2 extends Applet implements ActionListener,ItemListener { Frame f2; /* Frame where charts are graphed */ Panel p1, /* Panel which holds the graph and quit */ /* buttons */ p2, /* Panel which holds the label to choose a */ /* graph */ p3, /* Panel which holds the graph choices */ p4, /* Panel which holds the title labels and */ /* units entries */ p5, /* Panel which holds the p5, p6 and p7 */ /* panels */ p6, /* Panel which holds the entry field for the */ /* x and y values */ p7; /* Panel which holds the # of pts choice box */ Button graph, /* Button to graph the charts */ quit; /* Button to quit the applet */ CheckboxGroup choice_group; /* Group of check boxes to choose */ /* a graph */ Checkbox[] choices; /* Check boxes used to choose a graph */ Choice numpts; /* Pull down box to choose number of points */ /* to be graphed */ TextField title, /* Text field to enter title */ xcoord, /* Text field to enter label of x coord */ ycoord, /* Text field to enter label of y coord */ xunit, /* Text field to enter units of x coord */ yunit; /* Text field to enter units of y coord */ TextField valuesx[] = new TextField[12]; /* Arrays of x */ TextField valuesy[] = new TextField[12]; /* and y values */ int max = 400; /* Maxinum number of points */ int points; /* Number of points being entered */ int x1[] = new int[max]; /* Arrays of x and y values */ int y1[] = new int[max]; int x2[] = new int[max]; int y2[] = new int[max]; int x4[] = new int[max]; /* Arrays of sorted x and y */ int y4[] = new int[max]; /* values */ String xval[] = new String[max]; /* Array of string values */ /* of x */ int startx1 = 0, /* starting point of first x value */ space = 30, /* Space between points */ top = 350, /* Top of chart */ i, /* counters */ c=6, mean; /* mean */ Font theFont; /* Font used on graphic */ String ychar; /* hold string of y label and units */ Graphics g1; /* Graphics which draws charts */ double sum, /* sum */ xcf, /* x conversion factor */ ycf; /* y conversion factor */ String ycoord1, /* labeld of y axis */ yunit1; /* units of y axis */ public void init() { int x; /* resize, move and set colors on applet */ this.resize(400,400); this.move(0,150); this.setBackground(Color.white); // this.setForeground(Color.darkGray); this.setForeground(Color.red); /* create graphics g1 */ g1 = this.getGraphics(); /* create frame f2, resize, move and set colors on it */ f2 = new Frame("Graph"); this.show(); f2.resize(400,400); f2.move(500,150); f2.setBackground(Color.cyan); f2.setForeground(Color.darkGray); /* Create panel p1 and add graph and quit buttons to it and add p1 */ /* to frame f2 */ Panel p1 = new Panel(); graph = new Button("Graph it"); quit = new Button("Quit"); p1.setLayout(new BorderLayout()); p1.add("East",graph); p1.add("West",quit); f2.add("South",p1); /* create panels p2 and p3. Add choice box label to p2. Add choice */ /* box to p3. Add p2 to p3. Add p3 to f2 */ Panel p2 = new Panel(); p2.setLayout(new BorderLayout()); p2.add("North",new Label("Choose a Type of Graph")); Panel p3 = new Panel(); p3.setLayout(new GridLayout(2,3)); choice_group = new CheckboxGroup(); choices = new Checkbox[5]; choices[0] = new Checkbox("Pareto", choice_group,true); choices[1] = new Checkbox("Histogram", choice_group,false); choices[2] = new Checkbox("Correlation Chart", choice_group, false); choices[3] = new Checkbox("Run Chart", choice_group,false); choices[4] = new Checkbox("Control Chart", choice_group,false); p3.add(choices[0]); p3.add(choices[1]); p3.add(choices[2]); p3.add(choices[3]); p3.add(choices[4]); p2.add("West",p3); f2.add("North",p2); /* Create panels p4, p5, p6 and p7. Add texfields to p5. Add x,y */ /* inputs to p6. Add numpts choice boc to p7. Add p5, p6, p7 to p4 */ /* Add p4 to f2 */ Panel p4 = new Panel(); p4.setLayout(new BorderLayout()); Panel p5 = new Panel(); p5.setLayout(new GridLayout(10,1)); title = new TextField(15); xcoord = new TextField(15); ycoord = new TextField(15); xunit = new TextField(15); yunit = new TextField(15); p5.add(new Label("Title of Graph:")); p5.add(title); p5.add(new Label("Label of x-coordinate:")); p5.add(xcoord); p5.add(new Label("Label of y-coordinate:")); p5.add(ycoord); p5.add(new Label("Units of x-coordinate:")); p5.add(xunit); p5.add(new Label("Units of y-coordinate:")); p5.add(yunit); p4.add("West",p5); title.setText(" "); ycoord.setText(" "); xcoord.setText(" "); xunit.setText(" "); yunit.setText(" "); Panel p6 = new Panel(); p6.setLayout(new GridLayout(13,2)); p6.add(new Label("x-vals")); p6.add(new Label("y-vals")); for(i=0;i<12;i++) { valuesx[i] = new TextField(5); p6.add(valuesx[i]); valuesy[i] = new TextField(5); p6.add(valuesy[i]); } p4.add("Center",p6); Panel p7 = new Panel(); p7.setLayout(new GridLayout(10,1)); p7.add(new Label("# of pts")); numpts = new Choice(); numpts.addItem(""); numpts.addItem("1"); numpts.addItem("2"); numpts.addItem("3"); numpts.addItem("4"); numpts.addItem("5"); numpts.addItem("6"); numpts.addItem("7"); numpts.addItem("8"); numpts.addItem("9"); numpts.addItem("10"); numpts.addItem("11"); numpts.addItem("12"); p7.add(numpts); p4.add("East",p7); f2.add("Center",p4); f2.show(); quit.addActionListener(this); graph.addActionListener(this); for (x=0;x<5;x++) choices[x].addItemListener(this); numpts.addItemListener(this); } public void itemStateChanged(ItemEvent e) { int x; for (x=0;x<5;x++) { if (choices[x].getState()) { System.out.println("item" + choices[x].getState()); c = x; } } if (e.getSource() == numpts) { System.out.println("numpts is " + numpts.getSelectedIndex()); points = numpts.getSelectedIndex(); } } public void actionPerformed(ActionEvent e) { System.out.println ("action:" + e.getActionCommand()); System.out.println(e.getSource().toString()); if (e.getActionCommand() == "Graph it") { System.out.println ("graph it"); paint(g1); } ///if action is quit then quit the applet if (e.getActionCommand() == "Quit") { System.out.println ("quit it"); f2.hide(); f2.dispose(); } } public void paintpareto(Graphics g1) { /* calculated conversion factor for y-axis */ System.out.println("pareto diagram"); for(i=0;i 0) { g1.setColor(Color.black); g1.drawLine(20 + x2[i-1],top - y2[i-1],20 + x2[i], top - y2[i]); } } } // end run chart public void paintcontrol(Graphics g1) { /* calculate x and y conversion factors */ for(i=0;i 0) { g1.setColor(Color.black); g1.drawLine(20 + x2[i-1],top- y2[i-1],20 + x2[i], top - y2[i]); } } /* calculte mean and standard deviation */ mean = (int)(sum / (double)i); double meanx = (x3 / (double)i); double total = 0; for(i=0;i