uk.co.jscieng
Class SciGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--java.applet.Applet
                          |
                          +--uk.co.jscieng.SciGraphBase
                                |
                                +--uk.co.jscieng.SciGraph

public abstract class SciGraph
extends uk.co.jscieng.SciGraphBase

The SciGraph class is the interface into the JSGL, a Scientific Graphics Library for Java. This library was written for the book `Introductory Java for Scientists and Engineers' by Richard J. Davies and is described at much greater length in that book. The methods that you should use are those declared as public static.

Note that this library can be used to write either applications or applets. In the first case, write your application as normal using a main method:

 public static void main(String[] argv)
 
And simply call the methods of SciGraph as desired. In the second case, you should define a class that extends SciGraph, and write a main method with the prototype:
 public void main()
 
Your class is then a subclass of Applet and should be used the class that you name in the code part of the Applet tag in your HTML.

You can write a program which can be run in both ways by writing:

 public class MyClass extends SciGraph
 {
   public static void main(String[] argv)
   {
     ...
   }
 
   public void main()
   {
     main(new String[1])
   }
 }
 

Version:
1.0
Author:
Richard J. Davies
See Also:
Serialized Form

Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
SciGraph()
           
 
Method Summary
static void clear()
          clear removes all previous drawing from the graph window.
static void functionPlot(Plottable p)
          A version of functionPlot that defaults to drawing the graph in black using the whole width of the graph window with one point every 10 pixels horizontally.
static void functionPlot(Plottable p, java.awt.Color c)
          A version of functionPlot that defaults to drawing the graph using the whole width of the graph window with one point every 10 pixels horizontally.
static void functionPlot(Plottable p, java.awt.Color c, double pixelgap)
          A version of functionPlot that defaults to drawing the graph using the whole width of the graph window.
static void functionPlot(Plottable p, double pixelgap)
          A version of functionPlot that defaults to drawing the graph in black using the whole width of the graph window.
static void functionPlot(Plottable p, double left, double right)
          A version of functionPlot that defaults to drawing the graph in black with one point every 10 pixels horizontally.
static void functionPlot(Plottable p, double left, double right, java.awt.Color c)
          A version of functionPlot that defaults to drawing the graph with one point every 10 pixels horizontally.
static void functionPlot(Plottable p, double left, double right, java.awt.Color c, double pixelgap)
          functionPlot draws a graph of a function.
static void functionPlot(Plottable p, double left, double right, double pixelgap)
          A version of functionPlot that defaults to black.
static void line(double xend, double yend)
          A version of line that continues drawing from the last point to be drawn in the graph, continuing using that same color that that point was drawn in.
static void line(double xend, double yend, java.awt.Color c)
          A version of line that continues drawing from the last point to be drawn in the graph.
static void line(double xstart, double ystart, double xend, double yend)
          A version of line that defaults to a black line.
static void line(double xstart, double ystart, double xend, double yend, java.awt.Color c)
          line draws a line in the graph window between two points.
static void linePlot(double[] array)
          A version of linePlot that draws the graph across the entire width of the graph window, using black.
static void linePlot(double[] array, java.awt.Color c)
          A version of linePlot that draws the graph across the entire width of the graph window.
static void linePlot(double[] array, double left, double right)
          A version of linePlot that defaults to black.
static void linePlot(double[] array, double left, double right, java.awt.Color c)
          linePlot draws a line graph from a set of values stored in array.
static void parametricPlot(Plottable x, Plottable y)
          A version of parametricPlot that defaults to drawing the graph in black with a range from 0 to 1 and with fifty points.
static void parametricPlot(Plottable x, Plottable y, java.awt.Color c)
          A version of parametricPlot that defaults to drawing the graph with a range from 0 to 1 and with fifty points.
static void parametricPlot(Plottable x, Plottable y, java.awt.Color c, int points)
          A version of parametricPlot that defaults a range from 0 to 1.
static void parametricPlot(Plottable x, Plottable y, double start, double finish)
          A version of parametricPlot that defaults to drawing the graph in black with fifty points.
static void parametricPlot(Plottable x, Plottable y, double start, double finish, java.awt.Color c)
          A version of parametricPlot that defaults to drawing the graph with fifty points.
static void parametricPlot(Plottable x, Plottable y, double start, double finish, java.awt.Color c, int points)
          parametricPlot draws a graph in which both x and y coordinates are functions of a third variable.
static void parametricPlot(Plottable x, Plottable y, double start, double finish, int points)
          A version of parametricPlot that defaults to black.
static void parametricPlot(Plottable x, Plottable y, int points)
          A version of parametricPlot that defaults to drawing the graph in black with a range from 0 to 1.
static void point(double x, double y)
          A version of point that defaults to black points.
static void point(double x, double y, java.awt.Color c)
          point plots a single point in the graph window.
static void print(boolean b)
          A version of print that takes a boolean.
static void print(char c)
          A version of print that takes a character.
static void print(char[] s)
          A version of print that takes an array of characters.
static void print(double d)
          A version of print that takes a double.
static void print(float f)
          A version of print that takes a floating point number.
static void print(int i)
          A version of print that takes an integer.
static void print(long l)
          A version of print that takes a long integer.
static void print(java.lang.Object obj)
          A version of print that takes an object.
static void print(java.lang.String s)
          print outputs a line of text into the text window.
static void println()
          A version of println that just moves to a new line.
static void println(boolean b)
          A version of println that takes a boolean.
static void println(char c)
          A version of println that takes a character.
static void println(char[] s)
          A version of println that takes an array of characters.
static void println(double d)
          A version of println that takes a double.
static void println(float f)
          A version of println that takes a floating point number.
static void println(int i)
          A version of println that takes an integer.
static void println(long l)
          A version of println that takes a long integer.
static void println(java.lang.Object obj)
          A version of println that takes an object.
static void println(java.lang.String s)
          println outputs a line of text into the text window and then moves to the start of a new line of output.
static java.lang.String readln()
          readln stops execution of your program, allows the user to enter some text and then returns that text as a string when they click on the Input button in the window.
static void showGraph(double left, double right, double bottom, double top)
          An version of showGraph defaulting to 300 pixels each way.
static void showGraph(double left, double right, double bottom, double top, int width, int height)
          showGraph creates and shows a graph window.
static void showText()
          An overloaded version of showText which defaults to a window 80 characters wide and 24 characters tall.
static void showText(int width, int height)
          showText creates and shows the text window in which print, println and readln occur.
static void stepPlot(double[] array)
          A version of stepPlot that draws the bars in black across the entire width of the graph window.
static void stepPlot(double[] array, java.awt.Color c)
          A version of stepPlot that draws the bars across the entire width of the graph window.
static void stepPlot(double[] array, double left, double right)
          A version of stepPlot that defaults to black.
static void stepPlot(double[] array, double left, double right, java.awt.Color c)
          stepPlot draws a bar-chart based on an array of values.
static java.lang.String stringOf(double x, int n)
          stringOf converts a floating point number into a string containing a fixed number of digits.
 
Methods inherited from class uk.co.jscieng.SciGraphBase
destroy, init, main, paint
 
Methods inherited from class java.applet.Applet
getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFont, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SciGraph

public SciGraph()
Method Detail

showText

public static void showText(int width,
                            int height)
showText creates and shows the text window in which print, println and readln occur.
Parameters:
width - The width of the window in characters
height - The height of the window in characters
See Also:
print(java.lang.String), println(java.lang.String), readln()

showText

public static void showText()
An overloaded version of showText which defaults to a window 80 characters wide and 24 characters tall.

print

public static void print(java.lang.String s)
print outputs a line of text into the text window. The output does not automatically move to a new line after this. This command corresponds to java.lang.System.out.print.
Parameters:
s - The string to be written.
See Also:
println(java.lang.String)

print

public static void print(java.lang.Object obj)
A version of print that takes an object.

print

public static void print(char[] s)
A version of print that takes an array of characters.

print

public static void print(char c)
A version of print that takes a character.

print

public static void print(int i)
A version of print that takes an integer.

print

public static void print(long l)
A version of print that takes a long integer.

print

public static void print(float f)
A version of print that takes a floating point number.

print

public static void print(double d)
A version of print that takes a double.

print

public static void print(boolean b)
A version of print that takes a boolean.

println

public static void println(java.lang.String s)
println outputs a line of text into the text window and then moves to the start of a new line of output.
Parameters:
s - The string to be written.
See Also:
print(java.lang.String)

println

public static void println()
A version of println that just moves to a new line.

println

public static void println(java.lang.Object obj)
A version of println that takes an object.

println

public static void println(char[] s)
A version of println that takes an array of characters.

println

public static void println(char c)
A version of println that takes a character.

println

public static void println(int i)
A version of println that takes an integer.

println

public static void println(long l)
A version of println that takes a long integer.

println

public static void println(float f)
A version of println that takes a floating point number.

println

public static void println(double d)
A version of println that takes a double.

println

public static void println(boolean b)
A version of println that takes a boolean.

stringOf

public static java.lang.String stringOf(double x,
                                        int n)
stringOf converts a floating point number into a string containing a fixed number of digits.
Parameters:
x - The floating point number.
n - The number of digits to return.
Returns:
A string of fixed length representing the number.

readln

public static java.lang.String readln()
readln stops execution of your program, allows the user to enter some text and then returns that text as a string when they click on the Input button in the window. Execution of your program then continues.
Returns:
The string that the user typed.

showGraph

public static void showGraph(double left,
                             double right,
                             double bottom,
                             double top,
                             int width,
                             int height)
showGraph creates and shows a graph window. The window is width pixels wide and height pixels tall on screen. However, internally it uses a coordinate system that is defined by left, right, bottom and top.
Parameters:
left - The left hand edge of the window in internal coordinates.
right - The right hand edge of the window in internal coordinates.
bottom - The bottom edge of the window in internal coordinates.
top - The top edge of the window in internal coordinates.
width - The width of the window in pixels.
height - The height of the window in pixels.

showGraph

public static void showGraph(double left,
                             double right,
                             double bottom,
                             double top)
An version of showGraph defaulting to 300 pixels each way.

clear

public static void clear()
clear removes all previous drawing from the graph window.

point

public static void point(double x,
                         double y,
                         java.awt.Color c)
point plots a single point in the graph window.
Parameters:
x - The x-coordinate of the point.
y - The y-coordinate of the point.
c - The color of the point.

point

public static void point(double x,
                         double y)
A version of point that defaults to black points.

line

public static void line(double xstart,
                        double ystart,
                        double xend,
                        double yend,
                        java.awt.Color c)
line draws a line in the graph window between two points.
Parameters:
xstart - The x-coordinate of the start of the line.
ystart - The y-coordinate of the start of the line.
xend - The x-coordinate of the end of the line.
yend - The y-coordinate of the end of the line.
c - The color of the line.

line

public static void line(double xstart,
                        double ystart,
                        double xend,
                        double yend)
A version of line that defaults to a black line.

line

public static void line(double xend,
                        double yend,
                        java.awt.Color c)
A version of line that continues drawing from the last point to be drawn in the graph.

line

public static void line(double xend,
                        double yend)
A version of line that continues drawing from the last point to be drawn in the graph, continuing using that same color that that point was drawn in.

functionPlot

public static void functionPlot(Plottable p,
                                double left,
                                double right,
                                java.awt.Color c,
                                double pixelgap)
functionPlot draws a graph of a function. The function is passed using a Plottable object, and the graph is drawn for x values between left and right. The graph is drawn in the color c with one point every pixelgap pixels horizontally across the screen.
Parameters:
p - A Plottable object containing the function to draw.
left - The left hand end of the range in which to draw it.
right - The right hand end of the range in which to draw it.
c - The color in which to draw it.
pixelgap - The number of pixels horizontally across the screen between points.
See Also:
Plottable, parametricPlot(uk.co.jscieng.Plottable, uk.co.jscieng.Plottable, double, double, java.awt.Color, int), stepPlot(double[], double, double, java.awt.Color), linePlot(double[], double, double, java.awt.Color)

functionPlot

public static void functionPlot(Plottable p,
                                double left,
                                double right,
                                double pixelgap)
A version of functionPlot that defaults to black.

functionPlot

public static void functionPlot(Plottable p,
                                java.awt.Color c,
                                double pixelgap)
A version of functionPlot that defaults to drawing the graph using the whole width of the graph window.

functionPlot

public static void functionPlot(Plottable p,
                                double pixelgap)
A version of functionPlot that defaults to drawing the graph in black using the whole width of the graph window.

functionPlot

public static void functionPlot(Plottable p,
                                double left,
                                double right,
                                java.awt.Color c)
A version of functionPlot that defaults to drawing the graph with one point every 10 pixels horizontally.

functionPlot

public static void functionPlot(Plottable p,
                                double left,
                                double right)
A version of functionPlot that defaults to drawing the graph in black with one point every 10 pixels horizontally.

functionPlot

public static void functionPlot(Plottable p,
                                java.awt.Color c)
A version of functionPlot that defaults to drawing the graph using the whole width of the graph window with one point every 10 pixels horizontally.

functionPlot

public static void functionPlot(Plottable p)
A version of functionPlot that defaults to drawing the graph in black using the whole width of the graph window with one point every 10 pixels horizontally.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  double start,
                                  double finish,
                                  java.awt.Color c,
                                  int points)
parametricPlot draws a graph in which both x and y coordinates are functions of a third variable. The functions are passed using Plottable objects, and the graph is drawn for values of the third variable between start and finish. The graph is drawn in the color c with one point every step across the range of the third variable.
Parameters:
x - A Plottable object mapping the third variable to x.
y - A Plottable object mapping the third variable to y.
start - The start of the range of the third variable.
finish - The end of the range of the third variable.
c - The color in which to draw it.
points - The number of points to calculate for the graph.
See Also:
Plottable, functionPlot(uk.co.jscieng.Plottable, double, double, java.awt.Color, double), stepPlot(double[], double, double, java.awt.Color), linePlot(double[], double, double, java.awt.Color)

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  double start,
                                  double finish,
                                  int points)
A version of parametricPlot that defaults to black.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  java.awt.Color c,
                                  int points)
A version of parametricPlot that defaults a range from 0 to 1.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  int points)
A version of parametricPlot that defaults to drawing the graph in black with a range from 0 to 1.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  double start,
                                  double finish,
                                  java.awt.Color c)
A version of parametricPlot that defaults to drawing the graph with fifty points.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  double start,
                                  double finish)
A version of parametricPlot that defaults to drawing the graph in black with fifty points.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y,
                                  java.awt.Color c)
A version of parametricPlot that defaults to drawing the graph with a range from 0 to 1 and with fifty points.

parametricPlot

public static void parametricPlot(Plottable x,
                                  Plottable y)
A version of parametricPlot that defaults to drawing the graph in black with a range from 0 to 1 and with fifty points.

stepPlot

public static void stepPlot(double[] array,
                            double left,
                            double right,
                            java.awt.Color c)
stepPlot draws a bar-chart based on an array of values. The values in arrayare drawn with equal width bars between the edge of an interval defined by left and right. They are drawn in the color c.
Parameters:
array - The values to use in the bar chart.
left - The left hand edge of the chart.
right - The right hand edge of the chart.
c - The color of the chart.
See Also:
functionPlot(uk.co.jscieng.Plottable, double, double, java.awt.Color, double), parametricPlot(uk.co.jscieng.Plottable, uk.co.jscieng.Plottable, double, double, java.awt.Color, int), linePlot(double[], double, double, java.awt.Color)

stepPlot

public static void stepPlot(double[] array,
                            double left,
                            double right)
A version of stepPlot that defaults to black.

stepPlot

public static void stepPlot(double[] array,
                            java.awt.Color c)
A version of stepPlot that draws the bars across the entire width of the graph window.

stepPlot

public static void stepPlot(double[] array)
A version of stepPlot that draws the bars in black across the entire width of the graph window.

linePlot

public static void linePlot(double[] array,
                            double left,
                            double right,
                            java.awt.Color c)
linePlot draws a line graph from a set of values stored in array. The points of the graph are evenly distributed across the interval between left and right and the lines between them are drawn in the color c.
Parameters:
array - The values for the point on the graph.
left - The left hand edge of the graph.
right - The right hand edge of the graph.
c - The color of the graph.
See Also:
functionPlot(uk.co.jscieng.Plottable, double, double, java.awt.Color, double), parametricPlot(uk.co.jscieng.Plottable, uk.co.jscieng.Plottable, double, double, java.awt.Color, int), stepPlot(double[], double, double, java.awt.Color)

linePlot

public static void linePlot(double[] array,
                            double left,
                            double right)
A version of linePlot that defaults to black.

linePlot

public static void linePlot(double[] array,
                            java.awt.Color c)
A version of linePlot that draws the graph across the entire width of the graph window.

linePlot

public static void linePlot(double[] array)
A version of linePlot that draws the graph across the entire width of the graph window, using black.