package ts; /* * Mapa Logístico para Série Temporal * Por Rogério Neves * LSI- USP */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class Map extends Applet implements ActionListener { Scrollbar sb1; Scrollbar sb2; PicCanvas canvas; Panel p1; Panel p2; Label l1; Label l2; Label l3; public TextField s; public TextField e; public TextField t; public void init() { Button b = null; setLayout(new BorderLayout()); add("Center", canvas = new PicCanvas()); add("South", p1 = new Panel()); p1.setLayout(new BorderLayout()); p1.add("North",sb1 = new Scrollbar()); sb1.setMaximum(1010); sb1.setOrientation(0); sb1.setValue(550); sb1.addAdjustmentListener(new java.awt.event.AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent ev) { sb1_adjustmentValueChanged(ev); } }); p1.add("Center",sb2 = new Scrollbar()); sb2.setMaximum(4010); sb2.setOrientation(0); sb2.setValue(3550); sb2.addAdjustmentListener(new java.awt.event.AdjustmentListener() { public void adjustmentValueChanged(AdjustmentEvent ev) { sb2_adjustmentValueChanged(ev); } }); p1.add("South", p2 = new Panel()); p2.add(l1 = new Label("Xo")); p2.add(s = new TextField(".55", 6)); s.addActionListener(this); p2.add(l2 = new Label(" mu")); p2.add(e = new TextField("3.55", 6)); e.addActionListener(this); p2.add(l3 = new Label(" step")); p2.add(t = new TextField("5", 2)); t.addActionListener(this); p2.add(b = new Button("Draw")); b.addActionListener(this); p2.add (b = new Button("Info")); b.addActionListener(this); p2.add (b = new Button("Quit")); b.addActionListener(this); } public void destroy() { remove(canvas); } public void start() { setEnabled(true); } public void stop() { setEnabled(false); } public void processEvent(AWTEvent e) { if (e.getID() == Event.WINDOW_DESTROY) { System.exit(0); } } public static void main(String[] args) { Map M = new Map(); Frame f; f = new Frame("Mapa Logistico") { protected void processWindowEvent(WindowEvent ev) { super.processWindowEvent(ev); if (ev.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } public synchronized void setTitle(String title) { super.setTitle(title); enableEvents(AWTEvent.WINDOW_EVENT_MASK); } }; f.add("Center", M); f.setSize(600, 500); f.show(); M.init(); M.start(); f.setVisible(true); } public String getAppletInfo() { return "Logistic Map for\nTime-series\nBy Rogério Neves."; } void sb1_adjustmentValueChanged(AdjustmentEvent ev) { s.setText(Double.toString(((double)(sb1.getValue())/1000))); e.setText(Double.toString(((double)(sb2.getValue())/1000))); canvas.redraw(sb1.getValue(),sb2.getValue(),Integer.parseInt(t.getText().trim())); } void sb2_adjustmentValueChanged(AdjustmentEvent ev) { s.setText(Double.toString(((double)(sb1.getValue())/1000))); e.setText(Double.toString(((double)(sb2.getValue())/1000))); canvas.redraw(sb1.getValue(),sb2.getValue(),Integer.parseInt(t.getText().trim())); } public void actionPerformed(ActionEvent ev) { String label = ev.getActionCommand(); if (label.equals("Quit")) System.exit(0); if (label.equals("Info")) canvas.redraw(); double ss = Double.valueOf(s.getText().trim().toString()).doubleValue(); double ee = Double.valueOf(e.getText().trim().toString()).doubleValue(); if (ev.getSource().equals(s)) sb1.setValue((int)(ss*1000)); if (ev.getSource().equals(e)) sb2.setValue((int)(ee*1000)); canvas.redraw(ss,ee,Integer.parseInt(t.getText().trim())); } } class PicCanvas extends Canvas { public double xo=.55; public double mi=3.55; public int step=5; boolean info = false; public void paint(Graphics g) { Rectangle r = getBounds(); this.setBackground(Color.white); g.setColor(Color.yellow); for (int i = 1; i <= r.height / 10; i++) g.drawLine(0, i * 10, r.width, i * 10); for (int i = 1; i <= r.width / 10; i++) g.drawLine(i * 10, 0, i * 10, r.height); g.setColor(Color.black); g.drawRect(1,1,r.width-3,r.height-3); if (info) { this.info=false; g.drawString("Mapa logístico para série temporal" , 20, 20); g.drawString("Por Rogério Neves" , 20, 45); g.drawString("Laboratório de Sistemas Integáveis" , 20, 70); g.drawString("Universidade de São Paulo" , 20, 95); } else { g.drawString("1" , 3, 15); g.drawString("1" , 3, r.height / 2 - 4); g.drawString("_" , 3, r.height / 2 - 3); g.drawString("2" , 3, r.height / 2 + 10); g.drawString("0" , 3, r.height - 3); double xn = xo; double x = xo; int h = r.height-2; int t=14; while ((t+step)<=r.width) { xn = mi * xn * (1 - xn); g.setColor(Color.blue); g.drawLine(t,((int)(h-(x*h))),t+step,((int)(h-(xn*h)))); g.setColor(Color.black); g.drawRect(t-1,((int)(h-(x*h)-1)),2,2); t=t+step; x=xn; }} } public void redraw(int s, int e, int tt) { this.xo = ((double)s) / 1000; this.mi = ((double)e) / 1000; this.step = tt; repaint(); } public void redraw(double s, double e, int tt) { this.xo = s; this.mi = e; this.step = tt; repaint(); } public void redraw() { this.info = true; repaint(); } }