/////////////////////LINER//////////////////////////
/**@author Alan Cooper */
public class Liner extends AppletAppBean //implements Runnable
{
GraphWindow gw=new GraphWindow();
GraphStuff stuff=(GraphStuff)(gw.getStuff());
PointItem p1,p2;LineItem l; Random r=new Random();
Variable m=new Variable("m"),b=new Variable("b");
ParamSetManager psm;
public Liner(){
p1 = new PointItem(newPoint()); stuff.pointItems.addElement(p1);
p2 = new PointItem(newPoint()); stuff.pointItems.addElement(p2);
l=new LineItem(p1,p2); l.visible=false; stuff.lineItems.addElement(l);
GraphSetManager gsm=new GraphSetManager();
psm=gsm.getParamSetManager(); psm.noNewParamButton();
psm.addParameter(m);psm.addParameter(b);
//gsm.addNewGraph(new GraphItem("y=m*x+b") );//this doesn't work
because I
// haven't coded addNewGraph to identify and match up the params
// when adding a new graphItem to the gsm (should be doable though)
GraphItem theGraphItem=new GraphItem();//but/////////
gsm.addNewGraph(theGraphItem);/////////////this//////
theGraphItem.setGraphDef("y=m*x+b");/////////does////
stuff.include(gsm);
setBackground(new Color(255,255,220));
setSize(650,500);setLayout(null);
add(gw); gw.setBounds(220,0,400,480);
add(psm);psm.setBounds(20,100-80,220,160);
Label instructions1 = new Label("Set Parameters m, and b");
Label instructions2 = new Label("for line y=mx+b to hit");
Label instructions3 = new Label("the two plotted points");
add(instructions1);instructions1.setBounds(20,20,150,20);
add(instructions2);instructions2.setBounds(20,40,150,20);
add(instructions3);instructions3.setBounds(20,60,150,20);
Button hint=new Button("Hint");
add(hint); hint.setBounds(20,350,70,40);
hint.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){giveHint(true);}
}
);
Button setTarg=new Button("Reset");
add(setTarg); setTarg.setBounds(100,350,70,40);
setTarg.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){reset();}
} );
}//end constructor
void giveHint(boolean show){
l.visible=show; l.extend=show; l.showRect=show; l.plot(gw);
try{Thread.sleep(10);}catch(InterruptedException e){}
l.hlabel.setVisible(show);l.vlabel.setVisible(show);l.slopelabel.setVisible(show);
}
void reset(){
giveHint(false); m.setValue(0); b.setValue(0);
psm.showParamControls();//this should not be necessary
//somehow paramControler is not listening to param.setValue()???????????
p1.setPosition(newPoint());p2.setPosition(newPoint());
stuff.firePropertyChange("stuff",null,stuff);
}
MathPoint newPoint(){
double x=r.nextGaussian();
double y=r.nextGaussian();
return new MathPoint(x,y);
}
public void init(){setSize(650,500);}
public static void main(String[] args) {
AppletApp a=new Liner();
frameIt(a); }
}//endClass(Liner)