import java.awt.*;

import java.applet.*;

public class Henon extends Applet

{

public void init(){

setLayout(new BorderLayout());

setBackground(java.awt.Color.red);

HenonCanvas c = new HenonCanvas();

add("Center", c );

add("South", new HenonControls(c));

}

}

 

class HenonControls extends Panel {

Label k1 = new Label("x");

Label k2 = new Label("y");

Label k3 = new Label("a");

Label k4 = new Label("b");

TextField x;

TextField y;

TextField a;

TextField b;

HenonCanvas canvas;

public HenonControls(HenonCanvas canvas) {

this.canvas = canvas;

add(k1);

add(x = new TextField("0.1", 4));

add(k2);

add(y = new TextField("0.1", 4));

add(k3);

add(a = new TextField("1.245", 4));

add(k4);

add(b = new TextField("0.3", 4));

add(new Button("Draw"));

}

public boolean action(Event ev, Object arg) {

if (ev.target instanceof Button) {

String label = (String)arg;

canvas.redraw(Double.valueOf(x.getText().trim()).doubleValue(),

Double.valueOf(y.getText().trim()).doubleValue(),

Double.valueOf(a.getText().trim()).doubleValue(),

Double.valueOf(b.getText().trim()).doubleValue());

return true;

}

return false;

}

}

 

class HenonCanvas extends Canvas{

double init_x=0.1,init_y=0.1,fixed_a=1.245,fixed_b=0.4;

public HenonCanvas(){

resize(600,200);

}

public void paint(Graphics g) {

Henon_Map ex = new Henon_Map(g, init_x, init_y, fixed_a, fixed_b);

}

public void redraw(double x, double y, double a, double b) {

init_x = x;

init_y = y;

fixed_a = a;

fixed_b = b;

repaint();

}

}

class Henon_Map {

double init_x;

double init_y;

double fixed_a;

double fixed_b;

Henon_Map(Graphics g, double x, double y, double a, double b){

double x1,x0=x;

double y1,y0=y;

double fixed_a = a;

double fixed_b = b;

g.setColor(Color.blue);

g.drawString("" + -2, 5,220);

g.drawString("" + 0, 287,220);

g.drawString("" + 2, 580,220);

g.drawString("" + 2, 5,25);

g.setColor(Color.yellow);

for(int i=0;i<=10000;i++){

x1=(fixed_a - (x0*x0) + fixed_b*y0);

y0=x0;

x0=x1;

if (x1<=2 && x1>=-2 && y0<=2 && y0>=-2) {

g.drawLine((int)(150*(x0+2)),(int)(-50*(y0-2)),

(int)(150*(x0+2)),(int)(-50*(y0-2)));}

else { g.setColor(Color.white);

g.drawString("Trajectory has Exploded at " + i +"th Iterate.",200,200);

break;}

}

}

}