package tangentLine; import java.applet.*; import java.awt.*; import functionParser.*; import graphingApplet.*; public class TangentSlate extends ReportingSlate{ Ssub subscriber; private int pWidth; private int pHeight; Button clear; Button in; Button out; public TangentSlate(MessageCenter mcent, String name){ super(mcent,name); pWidth = 260; pHeight = 207; resize(pWidth,pHeight); subscriber = new Ssub("slopes",this); subscriber.intDataArray = new IntData[1]; subscriber.intDataArray[0] = new IntData("clicked",0); subscriber.doubleDataArray = new DoubleData[3]; subscriber.doubleDataArray[0] = new DoubleData("x_0",0.0); subscriber.doubleDataArray[1] = new DoubleData("y_0",0.0); subscriber.doubleDataArray[2] = new DoubleData("tangentSlope",0.0); subscriber.stringDataArray = new StringData[0]; subscriber.subscribe(mc); bp = new ButtonPad(2,3); in = new Button("zoom in"); bp.place(in,0,0); out = new Button("zoom out"); bp.place(out,0,2); clear = new Button("clear"); bp.place(clear,1,1); add("North",bp); can.resize(268,180); add("Center",can); } public void paint(Graphics g){ report(); }// END OF PAINT public void report(){ Graphics g = can.getGraphics(); g.setColor(Color.white); g.fillRect(0,0,255,180); g.setColor(Color.black); g.draw3DRect(0,0,255,179,true); //DRAW STRINGS HERE if(mc.readIntData("clicked") >0){ g.drawString("(x_0,y_0) = (" + formatter.formatDouble(mc.readDoubleData("x_0"),4) + "," + formatter.formatDouble(mc.readDoubleData("y_0"),3) + ")", 5,15); g.drawString("The tangent line slope is " + formatter.formatDouble(mc.readDoubleData("tangentSlope"),4),5,35); } }//END OF METHOD public boolean action(Event e,Object arg){ if(e.target instanceof Button){ if(((String)arg).equals("clear")){ mc.cleanParentInput(); mc.refreshParent(); } else if(((String)arg).equals("zoom in")){ mc.runNamedStndParentMeth("in",0,0); mc.refreshParent(); } else if(((String)arg).equals("zoom out")){ mc.runNamedStndParentMeth("out",0,0); mc.refreshParent(); } repaint(); return true; } else return false; } public Dimension getMinimumSize(){ return new Dimension(pWidth,pHeight);} public Dimension getPreferredSize(){ return new Dimension(pWidth,pHeight);} }