import java.awt.*; import java.awt.event.*; import java.applet.*; public class Henon extends Applet implements ActionListener { private double xmin = -2, xmax = 2, ymin = -2, ymax = 2; private double a = 1.4, b = -0.3, x = 0, y = 0; private Button start = new Button("Start"); private TextField inputA = new TextField("1.400"); private TextField inputB = new TextField("-0.30"); private TextField inputX = new TextField("0.000"); private TextField inputY = new TextField("0.000"); private boolean draw = false; public void init() { Panel input = new Panel(); input.setLayout(new FlowLayout()); input.add(new Label("a: ")); input.add(inputA); input.add(new Label("b: ")); input.add(inputB); input.add(new Label("X0: ")); input.add(inputX); input.add(new Label("Y0: ")); input.add(inputY); input.add(start); start.addActionListener(this); setLayout(new BorderLayout()); add("South", input); } public void paint(Graphics g) { g.drawRect(0,0, getSize().width-1, getSize().height-1); if (draw) { double xx = 0; for (int i = 0; i < 5000; i++) { xx = x; x = a - b*y - x*x; y = xx; } for (int i = 0; i < 50000; i++) { xx = x; x = a - b*y - x*x; y = xx; int ix = toScreen(x, getSize().width, xmin, xmax); int iy = toScreen(y, getSize().height, ymax, ymin); g.fillRect(ix, iy, 2, 2); } } } public void actionPerformed(ActionEvent ae) { if (ae.getSource() == start) { a = toDouble(inputA.getText()); b = toDouble(inputB.getText()); x = toDouble(inputX.getText()); y = toDouble(inputY.getText()); draw = true; repaint(); } } public int toScreen(double x, int iMax, double min, double max) { return (int)Math.round( iMax / (max - min) * (x - max) + iMax); } public double toDouble(String x) { try { Double num = new Double(x); return num.doubleValue(); } catch(Exception ie) { return 0.0; } } }