//****************************************************************************** // diffusion.java: Applet // //****************************************************************************** import java.applet.*; import java.awt.*; import java.util.Random; //import gjt.*; //============================================================================== // Main Class for applet diffusion // //============================================================================== public class Frap3 extends Applet { ThreeDBorder tdb = null; Frap3CanvasN dc = null; BarChart theChartRed=null; Button StartStop=new Button("Start"); boolean running=false; public void init(){ dc = new Frap3CanvasN(this); tdb = new ThreeDBorder(dc,5); theChartRed=new BarChart(Color.red,"Number within Circle",75.0,0.0); tdb.inset(); setLayout(new BorderLayout()); add("Center",tdb); add("South",theChartRed); add("North",StartStop); } public Insets insets(){ return new Insets(5,5,5,5); } public void start(){ dc.init(); //dc.start(); } public void stop(){ dc.stop(); } public boolean action(Event event, Object what){ if(event.target==StartStop){ if (running){ dc.stop(); running=false; StartStop.setLabel("Start"); }else{ dc.start(); running=true; StartStop.setLabel("Stop"); } } return true; } } class Frap3CanvasN extends Canvas implements Runnable //, StopwatchClient { // THREAD SUPPORT: // m_diffusion is the Thread object for the applet //-------------------------------------------------------------------------- Thread m_diffusion = null; Thread m_watch = null; private Applet applet; private final int NUM_PARTICLE=200; private final int CIRC_DIAM=80; private final double Fast=5.0, Slow=2.0; private Particle p[]; private Graphics m_g,m_r; private Image m_image,m_ready;// ,m_bg; private Dimension m_dimImage; private int Tick=0; private Color BG=new Color(153,204,204); private Point Start,UL,LR; private boolean ResetLocation=true; private boolean ImageReady=false; private int first=0, density=10, NumberIn1=0, NumberIn2=0; private int FrapCount=0; public Membrane m_Membrane; Circle m_circ; // diffusion Class Constructor //-------------------------------------------------------------------------- public Frap3CanvasN(Applet applet) { this.applet=applet; } // APPLET INFO SUPPORT: // The getAppletInfo() method returns a string describing the applet's // author, copyright date, or miscellaneous information. //-------------------------------------------------------------------------- public String getAppletInfo() { return "Name: Frap diffusion\r\n" + "Author: Joe Patlak\r\n" + "Created with Microsoft Visual J++ Version 1.0"; } // The init() method is called by the AWT when an applet is first loaded or // reloaded. Override this method to perform whatever initialization your // applet needs, such as initializing data structures, loading images or // fonts, creating frame windows, setting the layout manager, or adding UI // components. //-------------------------------------------------------------------------- public void init() { Dimension dim=size(); int nWidth=dim.width; int nHeight=dim.height; Start= new Point(15,15); UL=new Point(0,0); LR=new Point(nWidth-5,nHeight-5); m_circ=new Circle(dim.width/2, dim.height/2,CIRC_DIAM); int charge=1; p = new Particle[NUM_PARTICLE]; for (int i=0; i0) p[i].Active=false; } p[i].DrawParticle(m_g); } if (FrapCount>0){ FrapCount = ++FrapCount%6; m_circ.DrawFilled(m_g,Color.yellow); }else m_circ.Draw(m_g); m_r.drawImage(m_image,0,0,null); ((Frap3)applet).theChartRed.setFillValue(NumberIn1); ImageReady=true; repaint(); } } catch (InterruptedException e) { // TODO: Place exception-handling code here in case an // InterruptedException is thrown by Thread.sleep(), // meaning that another thread has interrupted this one stop(); } } } // MOUSE SUPPORT: // The mouseDown() method is called if the mouse button is pressed // while the mouse cursor is over the applet's portion of the screen. //-------------------------------------------------------------------------- public boolean mouseDown(Event evt, int x, int y) { //Start=new Point(x,y); //ResetLocation=true; //for (int i=0; i