import java.awt.*; import java.util.*; import java.applet.*; import graph.*; /************************************************************************* ** ** Applet plot3 ** T. W. Shattuck Colby College Version 1.0 Feb 2005 ** ************************************************************************** ** Based on example1.java and the 2D graph ** Java classes by Leigh Brookshaw (1996) ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ************************************************************************** ** ** The 3 data sets are loaded from the ** PARAM tag FUNCTION of the calling html, with the ** starting x value = minimum and then in equal increments. ** The each data set, the "function", is given as a ** comma delimited string of y values only. ** *************************************************************************/ public class plot3 extends Applet { Graph2D graph; DataSet data1; DataSet data2; DataSet data3; Axis xaxis; Axis yaxis; double data[]; int np = 500; int npd1 ; int npd2 ; int npd3 ; public void init() { double xf ; int count = 0; boolean error = false; double data[] = new double[2*np]; /* ** Get the passed parameters */ String fcnstr1 = getParameter("function1") ; String fcnstr2 = getParameter("function2") ; String fcnstr3 = getParameter("function3") ; String legendstr1 = getParameter("legendtext1") ; String legendstr2 = getParameter("legendtext2") ; String legendstr3 = getParameter("legendtext3") ; double minimum = Float.parseFloat(getParameter("minimum")); double increment = Float.parseFloat(getParameter("increment")); String xlabel = getParameter("xlabel") ; String ylabel = getParameter("ylabel") ; /* ** Create the Graph instance and modify the default behaviour */ graph = new Graph2D(); graph.drawzero = false; graph.drawgrid = false; graph.setGraphBackground(new Color(255,255,255)); setLayout( new BorderLayout() ); add("Center", graph); /* ** Get the first data Set. */ StringTokenizer en_str1 = new StringTokenizer(fcnstr1, ",") ; npd1 = en_str1.countTokens() ; for(int j=0; j 1) { data2 = graph.loadDataSet(data,npd2); data2.linecolor = new Color(0,255,0); data2.legend(400,120,legendstr2) ; data2.legendColor(Color.green) ; } /* ** Get the third data Set. */ StringTokenizer en_str3 = new StringTokenizer(fcnstr3, ",") ; npd3 = en_str3.countTokens() ; for(int j=0; j 1) { data3 = graph.loadDataSet(data,npd3); data3.linecolor = new Color(0,0,255); data3.legend(400,140,legendstr3) ; data3.legendColor(Color.blue) ; } /* ** Attach data sets to the Xaxis */ xaxis = graph.createAxis(Axis.BOTTOM); xaxis.attachDataSet(data1); if ( npd2 > 1 ) xaxis.attachDataSet(data2) ; if ( npd3 > 1 ) xaxis.attachDataSet(data3) ; xaxis.setTitleText(xlabel); xaxis.setTitleFont(new Font("TimesRoman",Font.PLAIN,20)); xaxis.setLabelFont(new Font("Helvetica",Font.PLAIN,15)); /* ** Attach both data sets */ yaxis = graph.createAxis(Axis.LEFT); yaxis.attachDataSet(data1); if ( npd2 > 1 ) yaxis.attachDataSet(data2) ; if ( npd3 > 1 ) yaxis.attachDataSet(data3) ; yaxis.setTitleText(ylabel); yaxis.setTitleFont(new Font("TimesRoman",Font.PLAIN,20)); yaxis.setLabelFont(new Font("Helvetica",Font.PLAIN,15)); } }