**Purpose:** This document outlines the basic steps that should be taken to create a Java program which does some mathematics and displays some graphics.

## Create some Java classes which represent mathematical objects.

Java is an object oriented programming language, meaning that the programmer creates "objects," which can "do" various things using method calls. The things an object might do when a method is called include changing the objects internal state, creating a new object, modifying an object that is passed as a parameter to the method.

Object oriented languages are well suited to represent mathematics, because we tend to thing of basic mathematical concepts as objects. Such a view goes back to Plato, who thought of mathematical objects as existing in a "world of ideal Forms."

In any case, the most basic mathematical concepts can naturally be converted into objects in Java:

- Numbers can be treated as Java objects as our Complex number class demonstrates.
- The LineSegment class gives a basic example of a geometric object implemented in Java.
- Mathematical functions can often be converted into Java objects as the Similarity class demonstrates.
- Now you can begin to imagine how more complicated objects could be constructed. A mathematical group after all consists of an identity element, a notion of group multiplication, and a inverse map. These things can all be understood in Java.

A good strategy for programming in Java is to take existing source code and modify it to suit your needs. Some more Java classes which implement mathematical ideas are available here:

- Package
**finitecyclicgroup**- File FiniteCyclicGroupDemo.java: Demonstrates the FiniteCyclicGroup and FiniteCyclicGroupElement classes.
- File FiniteCyclicGroupElement.java: Represents an element of the group Z mod n*Z for some integer n.
- File FiniteCyclicGroup.java: Represents the finite group Z modulo n*Z for integers n.

- Package
**number**- File BigComplex.java: High precision representation of complex numbers with floating point real and imaginary parts.
- File Complex.java: An alternate complex number class.
- File RationalDemo.java: Demonstrates the use of the Rational and RationalField classes.
- File RationalField.java: Class for performing algebraic operations on Rational numbers.
- File Rational.java: Represents a rational number (based on the BigInteger class).

- Package
**projectiveplane**- File Point.java: Represents a point in the projective plane.
- File ProjectiveTransform.java: Represents a projective transformation of the plane.

You can download all these files from this page.

As you create your mathematical objects, you should continually test what you are doing by writing simple executable programs that print the results of operations you have created.

## Displaying Mathematical Graphics

When creating a program to display mathematical graphics, you should follow the same ideas as above. You should modify existing source code to do what you want.

I've created three "templates" for graphical programs below.

- Package
**justdrawing**- File DrawingDemo.java: A simple program which draws some graphics in a window. Click here to run it using Java Web Start.
- File AffineTransformDemo.java: This is a simple demonstration of the use of an AffineTransform object to transform shapes before drawing. The class was based on the DrawingDemo class.

- Package
**drawsomething**- File Complex.java: A complex number class.
- File DrawSomething.java: Modifies the DrawingDemo class to draw a logarithmic spiral using the Complex number class.

- Package
**simplermouseinteraction**- File SimpleInteractionDemo.java: A program which allows the user to manipulate a disk in the plane. Click here to run it.
- File Drawing.java: Simple drawing program written at ICERM. This program was based off of the SimpleInteractionDemo class.

- Package
**mouseinteraction**- File InteractionDemo.java: A program which allows the user to plot some disks and move them around by dragging. Click here to run it.

- Package
**coordinatechanges**- File DemoFrame.java: This class implements a window which contains a DemoPanel. The window has a menu bar and a status bar. Click here to run it.
- File DemoPanel.java: This is a simple panel (part of a window) which dispays some mathematical graphics. It converts objects from math to screen coordinates before dispaying them using the TransformManager class.
- File TransformChangedListener.java: This is an interface that allows a TransformManager to notify a panel when the coordinate transformation has changed.
- File TransformManager.java: Manages a coordinate change from math-coordinates to screen coordinates. The class guarantees that a certain rectangle will be displayed.

You can download all these files from this page.

- Package

- Relevant parts of the Oracle's Java Tutorial:
- The section on Performing Custom Painting seems especially relevant.
- Introduction to Graphics2D: This describes how to draw basic geometric objects such as line segments, rectangles, ellipses, etc..
- There is an introduction to Swing and a more
extensive tutorial on swing. Swing hangles our menu
and status bar in the program from our
*coordinatechanges*

*package.*