IPApplet.java
 1 /*
 2  * IPApplet.java
 3  *
 4  * Created on March 31, 2004, 6:12 PM
 5  *
 6  *  Copyright 2004 Andrew Kaluzniacki
 7  *  All rights reserved.
 8  *  http://drewk.net
 9  */
10 
11 /**
12  *
13  * @author  drew
14  */
15 
16 public class IPApplet extends javax.swing.JApplet
17 implements  java.awt.event.ActionListener {
18     
19     /** Initializes the applet IPApplet */
20     public void init() {
21         initComponents();
22         
23         // create the model and associate it with the view
24         model = new IPModel();
25         view.setModel(model);
26         
27         //Set up the timer that will perform the animation.
28         timer = new javax.swing.Timer(timeStep, this);
29         timer.setCoalesce(false);
30         timer.start(); //Start the simulation.        
31     }
32     
33     /** This method is called from within the init() method to
34      * initialize the form.
35      * WARNING: Do NOT modify this code. The content of this method is
36      * always regenerated by the Form Editor.
37      */
38     private void initComponents() {
39         java.awt.GridBagConstraints gridBagConstraints;
40 
41         view = new IPView();
42 
43         getContentPane().setLayout(new java.awt.GridBagLayout());
44 
45         gridBagConstraints = new java.awt.GridBagConstraints();
46         gridBagConstraints.gridx = 0;
47         gridBagConstraints.gridy = 0;
48         gridBagConstraints.ipadx = 268;
49         gridBagConstraints.ipady = 128;
50         gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
51         getContentPane().add(view, gridBagConstraints);
52 
53     }
54     
55     /**
56      * Called by timer to update the model and view.
57      */    
58     public void actionPerformed(java.awt.event.ActionEvent e) {
59         model.update(timeStep/1000.0);
60         view.modelStateChanged();
61     }
62     
63     
64     // start the applet
65     public void start() {
66         timer.restart();
67     }
68     
69     // stop the applet
70     public void stop() {
71         timer.stop();
72     }
73     
74     
75     // Variables declaration - do not modify
76     private IPView view;
77     // End of variables declaration
78     
79     private IPModel model;
80     
81     private javax.swing.Timer timer;
82     
83     /**
84      * number of milliseconds per animation frame
85      */    
86     private int timeStep = 100;
87     
88 }
89