KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > BrusselatorApplet


1 /*
2  * Copyright 2003, Franz-Josef Elmer, All rights reserved
3  */

4 import jcckit.util.ConfigParameters;
5 import jcckit.util.AppletBasedConfigData;
6
7 import java.applet.*;
8 import java.awt.*;
9 import java.util.*;
10
11 public class BrusselatorApplet extends Applet {
12   private ConfigParameters _config
13       = new ConfigParameters(new AppletBasedConfigData(this));
14
15   public void init() {
16     setBackground(_config.getColor("background", getBackground()));
17     Brusselator brusselator = createBrusselator();
18     BrusselatorPlot plot = new BrusselatorPlot(_config, brusselator);
19
20     setLayout(new BorderLayout());
21     Panel p = new Panel();
22     p.setLayout(new FlowLayout(FlowLayout.LEFT));
23     p.add(new TimeView(brusselator));
24     add(p, BorderLayout.NORTH);
25     add(plot.getGraphicsCanvas(), BorderLayout.CENTER);
26     add(new BrusselatorController(brusselator).getControlPanel(),
27         BorderLayout.SOUTH);
28   }
29
30   private Brusselator createBrusselator() {
31     double dx = _config.getDouble("dx", 1);
32     double dt = _config.getDouble("dt", 0.05);
33     double size = _config.getDouble("L", 100);
34     Brusselator brusselator = new Brusselator(dx, dt, size);
35     brusselator.setNoiseFactor(_config.getDouble("noiseFactor", 1e-4));
36     brusselator.setAlpha(_config.getDouble("alpha", 1.8));
37     brusselator.setBeta(_config.getDouble("beta", 1));
38     brusselator.setD(_config.getDouble("d", 9));
39     brusselator.reset();
40     brusselator.addNoise();
41     double[] indices = _config.getDoubleArray("indices", new double[0]);
42     double[] u = _config.getDoubleArray("u", new double[0]);
43     double[] v = _config.getDoubleArray("v", new double[0]);
44     int len = Math.min(Math.min(u.length, v.length), indices.length);
45     for (int i = 0; i < len; i++) {
46       int index = (int) (indices[i] + 0.5);
47       brusselator.setU(index, u[i]);
48       brusselator.setV(index, v[i]);
49     }
50     return brusselator;
51   }
52 }
53
Popular Tags