import java.awt.*; import java.applet.Applet; import java.awt.event.*; public class roundoff extends Applet implements ActionListener{ // Applet for iteration of the Baker-map. Stefan Emet 1998. Label Label_X_0; TextField TextField_X_0; Button Button_Next, Button_Clear; double X_t, X_0=0.6; int t=0, x_position; boolean CLEAR=true,NEW=true; public void init(){ add(Label_X_0=new Label("X(0):")); add(TextField_X_0=new TextField(""+X_0,3)); add(Button_Next=new Button("Iterate")); add(Button_Clear=new Button("Clear")); } public void paint(Graphics g){ // width=400 and height=350 update(g); } public void update(Graphics g){ if (CLEAR){ x_position=0; g.setColor(Color.white); g.fillRect(0,100,399,224); g.setColor(Color.black); g.drawRect(0,100,399,224); g.drawRect(8,33,345,40); g.drawString("X(t+1) = B( X(t) ), where t=0,1,2, ...",15,50); g.drawString("B(x) = ",195,53); g.drawString("2 x , if x is in [0 , 1/2]",230,47); g.drawString("2 x - 1 , if x is in ]1/2, 1]",230,63); g.setColor(Color.red); g.drawString("Choose a startpoint X(0) from the interval [0,1]. Press Iterate-button to iterate B(X(0)).",5,95); g.setColor(Color.black); if (NEW){ X_t=X_0; NEW=false; } CLEAR=false; } if (t>0){ if (t%32==0){ CLEAR=true; } else if ((t-1)%16==0){ x_position=x_position==10 ? 200:10; } X_t=B(X_t); g.drawString("X("+t+") = "+X_t,x_position,115+((t-1)%16)*13); } } public double B(double x){ return x<=(double)1/2 ? 2*x:2*x-1; } public void actionPerformed(ActionEvent e){ Object source=e.getSource(); double in; in=Double.valueOf(TextField_X_0.getText()).doubleValue(); if (in != X_0){ X_0=in; CLEAR=NEW=true; t=0; } if (source.equals(Button_Next)){ t++; repaint(); } else if (source.equals(Button_Clear)){ CLEAR=NEW=true; t=0; repaint(); } } }// class roundoff