// July 2002, java applet by Oliver Knill for the CCP project // Vector Fields and Line Integrals by Oliver Knill and Dale Winter // Harvard University, Nov 15, 2002. See // http://www.math.duke.edu/education/ccp/materials/mvcalc/vfield/index.html // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License of the Free Software Foundation for // details. Compile with // javac pencil.java vectorfield.java lineintegral.java import java.applet.Applet; import java.awt.*; public class lineintegral extends Applet { static final long serialVersionUID = -1L; pencil pencil1; vectorfield vectorfield1; double sum1=0; // integral value int vectorfield_choice=1; // the chosen vectorfield boolean change=false; // only erase curve if change=true boolean found=false; // line integral has been found? public void init() { pencil1 = new pencil(500,500); vectorfield1 = new vectorfield(500,500); } public void paint(Graphics g) { pencil1.paint(g); repaint(); } public void update(Graphics g) { vectorfield1.menu(g,change,vectorfield_choice); if (change) { vectorfield1.erase(g); vectorfield1.erase_old_curve(g); change=false; } vectorfield1.update(g,vectorfield_choice); pencil1.update(g); } public boolean mouseDrag(Event event,int x,int y) { pencil1.read_pointer(x,y); vectorfield1.read_pointer(x,y); repaint(); return true; } public boolean mouseDown(Event event,int x,int y) { pencil1.read_pointer(x,y); vectorfield1.read_pointer(x,y); if ((Math.abs(y-150)<25) && (Math.abs(x)<50)) { vectorfield_choice=1; change=true; found=false; } if ((Math.abs(y-200)<25) && (Math.abs(x)<50)) { vectorfield_choice=2; change=true; found=false; } if ((Math.abs(y-250)<25) && (Math.abs(x)<50)) { vectorfield_choice=3; change=true; found=false; } if ((Math.abs(y-300)<25) && (Math.abs(x)<50)) { vectorfield_choice=4; change=true; found=false; } if ((Math.abs(y-350)<25) && (Math.abs(x)<50)) { vectorfield_choice=5; change=true; found=false; } if ((Math.abs(y-400)<25) && (Math.abs(x)<50)) { vectorfield_choice=6; change=true; found=false; } if ((Math.abs(y-450)<25) && (Math.abs(x)<50)) { vectorfield_choice=7; change=true; found=false; } repaint(); return true; } }