import java.awt.*; import java.applet.*; import java.awt.event.*; import java.awt.image.*; public class Logistic extends Applet { double a=4; double x0=0.618; Chronicle chronicle=new Chronicle(); Plot plot=new Plot(); Tree tree=new Tree(); CardLayout layout=new CardLayout(); Panel main=new Panel(layout); { main.add(chronicle,chronicle.toString()); main.add(plot,plot.toString()); main.add(tree,tree.toString()); } Choice choice=new Choice(); { choice.add(chronicle.toString()); choice.add(plot.toString()); choice.add(tree.toString()); choice.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { layout.show(main,choice.getSelectedItem()); } }); } Panel head=new Panel(new FlowLayout()); { head.add(choice); } public void init() { setLayout(new BorderLayout()); add(head,BorderLayout.NORTH); add(main,BorderLayout.CENTER); } double f(double x) { return f(a,x); } static double f(double a,double x) { return a*x*(1-x); } void setX0(double x0) { if (x0<0) this.x0=0; else if (x0>1) this.x0=1; else this.x0=x0; } void setA(double a) { if (a<0) this.a=0; else if (a>4) this.a=4; else this.a=a; } abstract class Canvas2 extends Canvas implements MouseListener,MouseMotionListener,KeyListener { int width,height; Image image; Thread daemon; public Canvas2() { setBackground(Color.white); addMouseListener(this); addMouseMotionListener(this); addKeyListener(this); } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { if (image==null) { width=getSize().width; height=getSize().height; image=createImage(width,height); } Graphics og=image.getGraphics(); og.clearRect(0,0,width,height); paint2(og); og.dispose(); g.drawImage(image,0,0,this); } public void paint2(Graphics g) {} void drawString(Graphics g,String string,int x,int y) { FontMetrics metrics=g.getFontMetrics(); int width=g.getFontMetrics().stringWidth(string); int height=g.getFont().getSize(); if (y-height<0) y+=height; if (x+width>this.width) x-=width; g.clearRect(x,y-height,width,height); g.drawString(string,x,y); } int plotX(double x) { return (int)((width-1)*x); } int plotY(double x) { return (int)((height-1)*(1-x)); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseClicked(MouseEvent e) {} public void mouseMoved(MouseEvent e) {} public void mouseDragged(MouseEvent e) {} public void keyPressed(KeyEvent e) {} public void keyReleased(KeyEvent e) {} public void keyTyped(KeyEvent e) {} } class Chronicle extends Canvas2 { boolean dragging; public void paint2(Graphics g) { double x=x0; for (int t=0;t