Grapher Ap and its Reusable GraphPanel Class
Examples and Extensions

The Grapher (as shown on the left) is a application that can be used to graph user supplied functions. It is based on the GraphPanel class that can be used in your applications. A number of examples are shown below. The Grapher like most applications of the GraphPanel class can be used as either an application or applet.

Some Simple uses of the Graph Panel Class

Simple Graph - displaying the Graph in a Dialog Box

[+/-] Show the dialog box.* is a nongraphic application that opens a dialog to display the graph. In this case the application supplied three functions and all the additional information to the Graph Panel. Required supporting code:

Simple Graph - displaying the Graph in a JFrame

[+/-] Show the JFrame.* is a JFrame application that displays the graph. This application supplies two functions and the other information to the Graph Panel. The graph size is fixed and will not change if the window size is changed. Required supporting code:

Simple Adjustable Size Graph displaying the Graph in JFrame

[+/-] Show the JFrame.

This application is similar to the previous one except the size of the graph will adjust to fill the window when the window size is changed. (The graph initially is the same size as in the previous ap but in the display, its window size has been reduced by the user.) Required supporting code:

Simple Graph - displaying the Graph in an Applet

[+/-] Show the Applet.

The* is a JApplet displayed by the appletviewer. This time the graph panel displays only a single curve but uses the polar coordinate option. Required supporting code:

More Complicated Graph Panel Applications

Animated Graph - displaying the Graph in either an Application or Applet

[+/-] Show the Graph.

The** can be an applet in the applet viewer, on its web page or part of an application. In this case 4 functions are displayed. They are animated under program control by the parameter t. The image was captured when t = 2. The program supplies the data values and the other information needed for the graph. Required supporting code:

Display Bezier Curves in either an Application or Applet

[+/-] Show the Graph.

The** can be displayed as a applet in the applet viewer, on its web page or used as an application. This program allows the user to pick 4 points (by clicking on the graph) and the new curve will be drawn. Required supporting code:

RegressionGrapher - Extending GraphPanel for Regression Lines and Curves

[+/-] Show the Graph.

The** can be displayed as an application. This ap determines and draws regression lines, quadratic, cubic, exponential and/or log curves for points suppied by user. The user can specify those points by clicking on the graph, typing the x and y coordinates or supplying a function. The code can also draw cubic or B-spines for the points.

This program demonstrates the capabilities of the PreGraphPanel extension to GraphPanel. This program includes GraphPanel and ExprEvaluator.

Unfortunately this ap can not be compiled because part of the source code is missing.

Required supporting code: and

Bar Graph - Extending GraphPanel with a New Kind of Point

[+/-] Show the Graph.

The** can be an applet displayed by the applet viewer, on its own web page or as an application. This ap draws a graph combining a normal curve with a bar graph.

GraphPanel is easy to extend because it includes two do-nothing methods extendedInit and paintExtendedPoint that are intended to be overridden. This program includes BarGraphPanel which extends GraphPanel by overriding both of them. The new paintExtendPoint method that draws a vertical bar. In addition, a new method drawBar allows the new type of data point. It is used instead of the normal moveTo and drawTo methods when sending points to the panel.

Required supporting code: and

Full Featured Graphing Ap - Extending GraphPanel with Preprocessing

[+/-] Show the Graph.

The** can be displayed as an applet using the applet viewer, shown on it web page or used as an application.

This ap can draw up to 4 user input functions. A great deal of flexibility is allowed. Parametric, logarithmic, and polar graphs are permitted. Over 30 different functions are available. The user can specify the graph's boundaries or they can calculated automatically. The user can specify colors and add titles. The resulting graphs can be printed.

Required supporting code: and

Compiling and running these aps.

Many of the Grapher related aps require numerous class files - as many as 21 for the Grapher. The GraphPanel used by all the aps requires 4 class files. The aps that can be run both as an application and as an applet require JAppletFrame and its 3 class files. In addition, the aps that allow the user to input expression require ExprEvaluater which uses 9 class files. Hence jar files are used extensively to reduce download time. Unfortunately, this complicates compiling and running those aps.

To simplify compiling and running these examples in Windows, .bat files are provided for each example:

   BarGraph compile       --- compile BarGraph
   BarGraph appletviewer  --- run in the AppletViewer
   BarGraph jar           --- run as an application using the jar file 
   BarGraph run           --- run as an application using class files
   BarGraph               --- run as an application using class files
   BarGraph ?             --- these instructions

The parameters like "compile" are case sensitive. The vary depending on the options for the particular example. To save loading time, use of the "jar" option is recommended whenever it is available.

*These ap are relatively simple files. As long as and are available, these files can be compiled using normal techniques. They can be run using normal java and appletviewer commands and normal techniques as an applet on a web page.

The following type of code can be used in a web page to run an applet if permitted by the browser:

    <object type="application/x-java-applet" height="500" width="400">
       <param name="code" value="SimpleGraphApplet" />
       <param name="archive" value="SimpleGraphApplet.jar" />
       <param name="permissions" value="sandbox" />
       Applet failed to run.  No Java plug-in was found or the applet was not signed properly.
**AnimatedGraph,,, and especially use at least 7 supporting class files. As result, the special bat files (for Windows) are strongly recommended.

Documentation for special classes

Java doc type documentation for the special classes used in these examples is available in the documentation folder.

Important comment about applets

At the time this package was written, it was rather easy to run a Java applet on a web page. Hence, in developing this package, there was a special effort to produce code that could be used as either a applet or application. Unfortunately, it was determined that it was too easy to use Java in malware. Various techniques were used to help prevent this. Currently modern browsers insist that applets are "digitally signed" to help verify they have not been altered to become malware. Unfortunately, it costs a significant amount of money to obtain a digital signature. This is not a particular problem for major Java developers but is for hobbyist like me especially since my code is freeware. Consequently, the applets have on this page have been replaced by static images. This is particularly unfortunate in the case of applets that allow user input.

Consequently, to run any of the code in this package, you will have to download the zip file and expand it. Developers having their own digital signature can use the code in their applet, sign it, and put it on their web pages. If you do so, it would be appreciated if you let me know about it.

Revised: July 25, 2018