While this could be done with the original classes, the
standardization of inter-object communication according to the jdk1.1 event
model and JavaBean conventions makes the process more transparent and perhaps
even accessible to non-programmers either through a gui 'builder' environment
or by using relatively simple code templates.
The code for the original applet was written with a substantial number of shared variables and cross-references between internal parts of these component classes, but in the new version they are more independent, and the code (see below) is much simpler.
//////////////////////////////////////////////
// Graphit.java
//
// Copyright © 1998-2001 Alan Cooper.
//
///////////////////////////////////////////
import qpr.util.beanstuff.*; import qpr.math.plotkit.*;
import qpr.math.alg.*; import qpr.math.d2g.*;
import qpr.math.svf.*; import qpr.math.grf.*;
import qpr.util.colorstuff.*;import qpr.util.*;
import java.awt.*;import java.beans.*;
import java.applet.Applet;
public class Graphit extends AppletAppBean
{
GraphWindow gw=new GraphWindow();
GraphSetManager gsm=new GraphSetManager();
ColorSelectPanel csp=gsm.getColorSelectPanel();
FunctionSetManager fsm=gsm.getFunctionSetManager();
ParamSetManager psm=gsm.getParamSetManager();
public Graphit(){setName("Graphit");
setSize(800,500); setLayout(null);
add(gw);gw.setBounds(200,0,400,480);
add(gsm);gsm.setBounds(0,0,200,200);
add(csp);csp.setBounds(0,200,200,200);
add(fsm);fsm.setBounds(600,200,200,200);
add(psm);psm.setBounds(600,0,200,200);
gw.show(gsm);
}
public void init(){setSize(800,500);}
public static void main(String[] args){
AppletApp a=new Graphit();
frameIt(a); }
}//endClass(Graphit)
To see what it does
Run the Applet |
For hints on usage
Check out the Help file |
For a line-by-line explanation
View Commented Code |
(Here I have put the ColorSelectPanel in a fixed position for simplicity, but - given the information that when activated it fires a 'PropertyChangeEvent' - writing the code to make it pop up as needed is not much harder. If you want you can check out the pop-up code now.)
If you want to actually experiment with modifying this code then you
will need a Java development environment and might want to skip ahead to
the section on compiling and running these programs.
Of course, there is much complexity hidden in the coding of the various components, but if I have designed and documented them well, it should be possible, without looking at their code, to easily rearrange and reconnect them to serve different purposes, with the functionality of the resulting applet adjusted so as to restrict or expand user options according to the paedagogical needs of the situation.
Here are two examples.
Run Elephant Applet | View bare Code | View Commented Code |
Run Liner Applet | View bare Code | View Commented Code |
These examples involve some classes which correspond to sub-components or 'properties' of the five main ones used in the first example. For greater control of the design of an applet, it is of course necessary to have more information about what classes are available and what actions or 'methods' they can be asked to perform. So now we shall look at the contents of the library in more detail.
The various components and subcomponents and their supporting classes of the gex library have been organized into a number of 'packages'. The JAVA 'package' concept is really intended to control what features of the classes are mutually accessible, with classes that need access to one another's innards grouped together and other classes given more limited access; but such divisions also often correspond to conceptually relevant groupings and the gex library is no exception.
There are packages dealing primarily with basic algebra, geometric objects, function concepts, and graphs&loci, with the graphical presentation tools in a separate package called the plotkit. Some frequently used tools of a general nature are also included in a 'utility' package.
The overall structure of the library is as follows:
qpr.util | |
qpr.util.beanstuff | |
qpr.util.colorstuff | |
qpr.util.commstuff | |
qpr.math | |
qpr.math.alg | |
qpr.math.svf | |
qpr.math.tbl | |
qpr.math.d2g | |
qpr.math.grf | |
qpr.math.plotkit |
This is at present quite rudimentary, but I will add more detailed comments
if anyone is actually interested in working with these classes. (So please
do let me know if you might do so, and if there are additional features
and or explanations that you think would be helpful.)
Otherwise, to compile and run your programs you will need a Java development environment. Sun's Java SoftwareDevelopmentKit (sdk) is available for download from their website. The package comes with an automatic installation option, and full documentation. But for just running these examples (and others built using the gex library), the process is very simple.
Once the java sdk is installed, just copy the directory containing this file and its subdirectories to the location of your choice. If you then edit any of the .java files in the code subdirectory, change both the class name and constructor name to (say) Classname (with the new name also being used to call the constructor in the main method), and save the result in a file called Classname.java, then on a Windows system you should be able to compile and run your new program by using the commands jc Classname the jrun Classname in the directory containing your copy of this file. (On other systems, the commands that you will need to run should be just the contents of the files jc.bat and jrun.bat - with the expression "%1" replaced by "Classname" .)