import java.awt.*; import java.applet.*; import java.lang.*; /* OilLine is an Applet that uses form data in a HTML Document (using Javascript), to draw a pipeline and two stations to study various strategies for finding the least distance using simple notions from a High SChool Geometry Course. inputs include the location and color of the pumping station S and the two locations A and B. This is designed to help students discover parallel lines and complementary angles. version 1.0 Novenber 5, 1998 -- Fr. Chris Thiel */ public class OilLine extends Applet { // globals String Title=""; int x[]; int y[]; int bx=0; int by=0; int hw =0; Object color[]; int n=3; //number of dots int yMax=200; float deltaX=0; float deltaY=0; boolean hint=false; boolean simple=false; double x0=0; double y0=0; Image img = null; int bgcolor =0; // the code... public void init() { bgcolor = Integer.parseInt(getParameter("bgcolor")); setBackground(new Color(bgcolor)); img = getImage(getCodeBase(), "topomap.gif"); String s; Title = new String("Press Redraw to Update"); // set up the array of balls x = new int[n]; y = new int[n]; color = new Color[n]; repaint(); } public void paint( Graphics g ) { if (!simple) {g.drawImage (img, 0,0,null);} g.drawString(Title, 30, 30 ); g.setColor(new Color(0xF08080)); //coral g.fillOval(x[0]-5, y[0]-10, 25, 15); //draw hint lines if (hint) { hw = Math.round((y[2]-100)/2); g.setColor(Color.green); g.drawLine(x[2],200-y[2],x[2],y[2]); g.drawLine(x[2],90,x[2]-10,90); g.drawLine(x[2]-10,90,x[2]-10,90); g.drawLine(x[2]-10,90,x[2]-10,99); g.drawLine(x[2]+5,100+hw,x[2]-5,100+hw); g.drawLine(x[2]-5,100-hw,x[2]+5,100-hw); g.drawLine(x[2]-10,99,x[2],99); g.drawLine(x[1],y[1],x[2],200-y[2]); } // g.setColor((Color)color[1]); g.fillRect(x[1]-5, y[1]-5, 11, 11); g.drawLine(x[0],y[0],x[1],y[1]); g.setColor((Color)color[2]); g.fillRect(x[2]-5, y[2]-5, 11, 11); g.drawLine(x[0],y[0],x[2],y[2]); g.setColor(Color.yellow); //draw labels g.setColor(Color.black); g.drawString(Integer.toString(x[0]), x[0],100); g.drawString("A", x[1]-3,y[1]+4); g.drawString("B", x[2]-3,y[2]+4); // make reference marks for (int j=25; j< 300; j = j+25){ g.drawLine(j,200,j,195); g.drawLine(j,0,j,5); } for (int j=25; j< 200; j = j+25){ g.drawLine(0,j,5,j); g.drawLine(295,j,300,j); } //draw the oilLIne g.setColor(Color.black); g.fillRect(0,99,300,2); // g.drawLine(bx[0],by[0],bx[1],by[1]); //g.fillOval(x[i]-1, y[i]-1, 3, 3); // g.fillOval(x[i+1]-1, y[i+1]-1, 3, 3); } public void setString(String aString) { Title = aString; repaint(); } public void setHint (int hintValue) { if(hintValue==0) {hint=false;} else {hint=true;} } public void setSimple(int simpleValue) { if(simpleValue==0) {simple=false;} else {simple=true;} } public void setPoint( int i, float xpt, float ypt, String colour) { x[i-1] = (int)(xpt); y[i-1] = 200-(int)(ypt); deltaX = x[1]-x[2]; deltaY = y[1]-y[2]; if (colour != null) { if (colour.equals("red")) { color[i-1] = Color.red; } else if (colour.equals("green")) { color[i-1] = Color.green; } else if (colour.equals("blue")) { color[i-1] = Color.blue; } else if (colour.equals("pink")) { color[i-1] = Color.pink; } else if (colour.equals("orange")) { color[i-1] = Color.orange; } else if (colour.equals("magenta")) { color[i-1] = Color.magenta; } else if (colour.equals("cyan")) { color[i-1] = Color.cyan; } else if (colour.equals("white")) { color[i-1] = Color.white; } else if (colour.equals("yellow")) { color[i-1] = Color.yellow; } else if (colour.equals("gray")) { color[i-1] = Color.gray; } else if (colour.equals("darkGray")) { color[i-1] = Color.darkGray; } else { color[i-1] = Color.black; } } else { color[i-1] = Color.black; } repaint(); } }