import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; // here comes the Map class Parameter { public int number; double K; double xb,xe,yb,ye; public Parameter() { K = 0.7; xb = 0; yb = 0; xe = 1; ye = 1; } } class Map extends Parameter { double psi[],theta[]; public Map() { number = 20; psi = new double [number]; theta = new double [number]; init(); } public void init() { double dpsi = (ye-yb)/number; for (int i = 0; i < number; i++) { psi[i] = yb + dpsi*i; theta[i] = 0.5; } } void integrate() { while (true) { singlestep(); break; } } void singlestep() { double psin, thetan; double twopi = 2.*Math.PI; for (int i = 0; i < number; i++) { psin = psi[i] + K/(twopi)*Math.sin(twopi*theta[i]); thetan = theta[i] + psin; while (thetan > xe) thetan -= (xe-xb); while (thetan < xb) thetan += (xe-xb); psi[i] = psin; theta[i] = thetan; } } } // here comes the graphics class mapCanvas extends Container { int number; public int x[],y[]; boolean reset_flag=true; public mapCanvas() { number = 20; x = new int [number]; y = new int [number]; } public synchronized void reset() { reset_flag=true; } public synchronized void paint(Graphics g) { if (reset_flag) { Dimension size = getSize(); g.setColor(Color.yellow); g.fillRect(0,0,size.width,size.height); reset_flag=false; } g.setColor(Color.blue); for (int i = 0; i < number; i++) { g.drawLine(x[i],y[i],x[i],y[i]); } } } public class Mapping extends Applet implements Runnable, AdjustmentListener, MouseListener { Map map; Thread killme = null; Scrollbar perturbation; mapCanvas canvas; public synchronized void init() { map=new Map(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; add(new Label("Perturbation K")); perturbation=new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 255); perturbation.setValue(45); perturbation.addAdjustmentListener(this); c.gridwidth = GridBagConstraints.REMAINDER; //end row gridbag.setConstraints(perturbation, c); add(perturbation); canvas = new mapCanvas(); canvas.addMouseListener(this); c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; gridbag.setConstraints(canvas, c); add(canvas); } public void start() { if(killme == null) { killme = new Thread(this); killme.start(); } } public void stop() { killme = null; } public void run() { while (killme != null) { try { map.integrate(); Dimension size; size = canvas.getSize(); for (int i = 0; i < map.number; i++) { canvas.x[i]=(int)((map.theta[i]-map.xb)*size.width/(map.xe-map.xb)); canvas.y[i]=(int)((map.ye-map.psi[i])*size.height/(map.ye-map.yb)); } Thread.sleep(10); } catch (InterruptedException e){} repaint(); } killme = null; } public synchronized void update(Graphics g) { paintAll(g); } public void adjustmentValueChanged(AdjustmentEvent evt) { if (evt.getSource() == perturbation) { map.init(); map.K = (perturbation.getValue())*2./128; canvas.reset(); } } public void mouseClicked(MouseEvent evt) { canvas.reset(); } public void mousePressed(MouseEvent evt) { } public void mouseReleased(MouseEvent evt) { } public void mouseEntered(MouseEvent evt) { } public void mouseExited(MouseEvent evt) { } }