import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.URL; public class Expon extends Applet { CurvePanel mainpanel; Button restartButton, mathReviewButton, applicationButton; Panel buttonpanel = new Panel(); Panel allbuttons = new Panel(); Scrollbar aslider, bslider, cslider; Panel sliderpanel = new Panel(); int a = 4; int b = -1; int c = -4; AdjustmentListener sliderListener = new AdjustmentListener() { public void adjustmentValueChanged( AdjustmentEvent e ) { a=aslider.getValue(); b=bslider.getValue(); c=cslider.getValue(); mainpanel.repaint(); } }; ActionListener restartListener = new ActionListener() { public void actionPerformed (ActionEvent e) { a=4; b=-1; c=-4; mainpanel.repaint(); } }; public void init() { setBackground(Color.white); int a = 4; int b = -1; int c = -4; mainpanel = new CurvePanel(); setLayout(new BorderLayout()); add("Center",mainpanel); mainpanel.init(); add("South",sliderpanel); sliderpanel.setLayout(new GridLayout(1,3)); aslider = new Scrollbar(Scrollbar.HORIZONTAL,4,1,-5,6); aslider.addAdjustmentListener(sliderListener); aslider.setBlockIncrement(1); sliderpanel.add(aslider); bslider = new Scrollbar(Scrollbar.HORIZONTAL,-1,1,-3,3); bslider.addAdjustmentListener(sliderListener); bslider.setBlockIncrement(1); sliderpanel.add(bslider); cslider = new Scrollbar(Scrollbar.HORIZONTAL,-4,1,-5,6); cslider.addAdjustmentListener(sliderListener); cslider.setBlockIncrement(1); sliderpanel.add(cslider); add("North",buttonpanel); buttonpanel.setLayout(new BorderLayout()); buttonpanel.add("East",allbuttons); allbuttons.setLayout(new GridLayout(1,1)); restartButton = new Button("restart"); restartButton.addActionListener(restartListener); allbuttons.add(restartButton); } public class CurvePanel extends Panel { public void init(){ } public void paint(Graphics g){ g.setColor(Color.black); g.drawRect(0,0,599,399); //box it g.drawLine(0, getSize().height / 2, getSize().width, getSize().height/ 2); g.drawLine(50, 0, 50, getSize().height-20); for (int i = -8; i<10; i++) { int y=getSize().height/2-i*getSize().height/20; g.drawLine(45, y, 55, y); g.drawString(""+i,58,y); } for (int i=1; i<4; i++) { double x=150.0*i+50; g.drawLine((int)x,getSize().height/2-5,(int)x,getSize().height/2+5); // if (i==1) {g.drawString("\u03c0",(int)x-3,getSize().height/2-7); // } else { g.drawString(""+i+"\u03c0",(int)x-5,getSize().height/2-7); } g.drawString(""+i+"",(int)x-5,getSize().height/2-7); } int sx = getSize().width/8-10; int sy = getSize().height - 8; g.drawString("a = " + a + " ", sx, sy); g.drawString("b = " + b + " ", sx + getSize().width/3, sy); g.drawString("c = " + c + " ", sx + getSize().width/3*2, sy); g.drawString("t",getSize().width-20,getSize().height/2-2); g.drawString("v",40,10); g.setFont(new Font("Dialog",0,16)); g.drawString("v = a*exp(b*t)+c",getSize().width/4-15,20); g.setColor(Color.red); for (int x = 0 ; x < getSize().width ; x=x+3) if (Math.abs(f(x))<1000) {g.drawLine(x, (int)f(x), x+3, (int)f(x+3)); g.drawLine(x, (int)f(x)+1, x+3, (int)f(x+3)+1); g.drawLine(x, (int)f(x)-1, x+3, (int)f(x+3)-1); } } double f(double x) { // return (-d-a*Math.sin(b*((x-50)/50-c)))*getSize().height/20 + getSize().height/2; return (-c-a*Math.exp(b*((x-50)/150)))*getSize().height/20 + getSize().height/2; } }