Graphing Applet Version 2.0 Copyright Anthony S. Pyzdrowski 1999, 2002 The Graphing applet will graph up to three functions and points. Equations and parameters can be preloaded through the htm file: When the "Window" parameter in the htm file is "true", the applet will run in it's own window. When the "Window" parameter in the htm file is "false" or not specified, the applet will run attached to the htm file. When the "Show" parameter in the htm file is "false" AND the "Window" parameter is "true", the applet will run in it's own window but the window will be invisible until the Show method is called from another Applet. The size of the graph is determined by the htm file WIDTH and HEIGHT parameters. The "WindowLeft" parameter specifies the left edge of the window. The "WindowTop" parameter specifies the top edge of the window. "WindowLeft" and "WindowTop" are also used to position the windows opened by the graphing Applet. The graph always has 10 horizontal and vertical divisions, each division is of size xscale or yscale. The initial graphing XMIN, XMAX, XSCALE, YMIN, YMAX, and YSCALE are also preloaded through the htm file parameters "xmin", "xmax", xscale", "ymin", "ymax", and "yscale". When no parameters are specified, XMIN is set to -10, XMAX is set to +10, and XSCALE is calculated. When equations are present, YMIN, YMAX, and YSCALE are set to the range determined by the current XMIN and XMAX. When there are no equations present, YMIN is set to -10, YMAX is set to +10, and YSCALE is calculated. When XMIN and XMAX are specified, XSCALE will be calculated regardless if it is specified in the htm file or not. When XMIN or XMAX is specified and XSCALE is specified in the htm file, the one not specified will be calculated by XSCALE and the one specified. When only XSCALE is specified in the htm file, XMIM and XMAX are calculated about 0.0. When only YMIN is specified in the htm file, YMAX and YSCALE are calculated. When only YMAX is specified in the htm file, YMIM and YSCALE are calculated. When both YMIN and YMAX are specified in the htm file, YSCALE is calculated. When YMIN or YMAX is specified and YSCALE is specified in the htm file, the one not specified will be calculated by YSCALE and the one specified. When only YSCALE is specified in the htm file, YMIM and YMAX are calculated about 0.0. The three equations can be loaded from the htm file through the parameters "Y1", "Y2", and "Y3". Features of the Graphing Applet: In the Graphing window, changing either XMIN or XMAX will use XSCALE to calculate the other. Changing XSCALE will calculate XMIN and XMAX maintaining the previous center. In the Graphing window, changing either YMIN or YMAX will use YSCALE to calculate the other. Changing YSCALE will calculate YMIN and YMAX maintaining the previous center. The Equation button enters a screen where the user can enter up to three, single variable, equations for graphing. The ENTER key must be pressed to accept an equation. Valid operators are: +, -, *, /, ^, (, and ). Multiplication MUST be specified with the *. PI and e are constants. Valid functions are: abs(), sqrt(), ln(), sin(), asin(), cos(), acos(), tan(), atan(). The first variable in an equation is the variable that will be used for the equation. In the Equation window, changing XMIN and/or XMAX will force XSCALE to be calculated. The Table button enters a screen which allows the user to evaluate the equations for given values. The Points button enters a screen where points can be placed on the graph. Entering x, y pairs or a single mouse click on the graph screen will deposit/remove points as long as the points window is opened. The Round button will round the displayed values to a proportion of the current scale. First round simply rounds the displayed values. The second round keeps the rounded values. The X and Y position is not kept. The Trace button will display a trace window which contains a set of radio buttons for the three equations. Selecting a radio button for a defined equation will enable tracing starting at the current X location. The < and > buttons will move the X value by the current x step size. Clicking on the screen will move the trace to that x position. Selecting the Tick circle will enable the drag feature. The double click centering and the drag and zoom features still function when tracing. The Grid button toggles the grid lines on and off. The Back button goes back through the move/zoom list. The Xin, Xout, Yin, Yout, In, and Out buttons are the Zoom buttons. The Scrollbars reposition the graph. The Reset button restores the graph to the original conditions when it was first opened. The Home button repositions the x and y axis to the original XMIN, XMAX, YMIN, and YMAX. A mouse double click on the graph screen centers on that point. A mouse single click on the graph screen gives the x, y coordinates of the point. A mouse click and drag on the graph screen will do a window zoom. Methods that can be called by other applets: String[][] getParameterInfo() String getAppletInfo() void Show(boolean) void SetPoints(List X, List Y) void GraphIt() boolean SetFunctions(String Yn, String Y) void IncludeOrigin() void SetX(double xmin, double xmax) void SetY(double ymin, double ymax) getParameterInfo returns information on: XMIN_Default double value XMAX_Default double value Xmin_Current double value Xmax_Current double value Xscale double value X_Current double value YMIN_Default double value YMAX_Default double value Ymin_Current double value Ymax_Current double value Yscale double value Y_Current double value WindowHeight int value WindowWidth int value Y1 String value Y2 String value Y3 String value Show will make the Graphing Applet window and all of it's support windows visible and invisible. Show will only work when the Graphing Applet is running in it's own window. SetPoints will initialize the Graphing Applet with X and Y points. The xmin, xmax, ymin, and ymax will be determined from these points. GraphIt will force a graph update and redraw. SetFunctions accepts Y1, Y2, or Y3 as String Yn. This parameter identifies which equation will be set. String Y is a valid infix equation. SetFunctions returns true if the equation was accepted and a false if the equation was in error. The ymin and ymax is calculated based on the current xmin and xmax. IncludeOrigin forces the origin including the X and Y axis to be in the original graph. SetX sets the initial xmin and xmax. SetY sets the initial ymin and ymax. An example call from another Applet located on the same htm page: import java.applet.*; ... public class YourApplet extends java.applet.Applet... { ... Applet grapher = null; String grapherName = "Graph"; //Get name to search for. grapher = getAppletContext().getApplet(grapherName); if (grapher != null) { //Use the instanceof operator to make sure the applet is a Graph object. if (grapher instanceof Graph.Graph) { ((Graph.Graph)grapher).SetPoints(XList, YList); if(((Graph.Graph)grapher).SetFunction("F1", "2*X^2-3*x")) { ... } ((Graph.Graph)grapher).SetX(MyXmin, MyXmax); ((Graph.Graph)grapher).SetY(MyYmin, MyYmax); ((Graph.Graph)grapher).IncludeOrigin(); ((Graph.Graph)grapher).Show(true); } } ... }