tutorial2.java

来自「MASON代表多主体邻里或网络仿真(Multi-Agent Simulator 」· Java 代码 · 共 84 行

JAVA
84
字号
package sim.app.tutorial1and2;import sim.engine.*;import sim.display.*;import sim.portrayal.grid.*;import java.awt.*;import javax.swing.*;public class Tutorial2 extends GUIState    {    public Display2D display;    public JFrame displayFrame;    public Tutorial2() { super(new Tutorial1(System.currentTimeMillis())); }        public Tutorial2(SimState state) { super(state); }        public String getName() { return "Conway's Game of Life"; }        public String getInfo()        {        return             "<H2>Conway's Game of Life</H2>" +            "<p>... with a B-Heptomino";         }        FastValueGridPortrayal2D gridPortrayal = new FastValueGridPortrayal2D();    public void setupPortrayals()        {        // tell the portrayals what to portray and how to portray them        gridPortrayal.setField(((Tutorial1)state).grid);        gridPortrayal.setMap(            new sim.util.gui.SimpleColorMap(                new Color[] {new Color(0,0,0,0), Color.blue}));        }        public void start()        {        super.start();              setupPortrayals();  // set up our portrayals        display.reset();    // reschedule the displayer        display.repaint();  // redraw the display        }        public void init(Controller c)        {        super.init(c);                // Make the Display2D.  We'll have it display stuff later.        Tutorial1 tut = (Tutorial1)state;        display = new Display2D(tut.gridWidth * 4, tut.gridHeight * 4,this,1);        displayFrame = display.createFrame();        c.registerFrame(displayFrame);   // register the frame so it appears in the "Display" list        displayFrame.setVisible(true);        // attach the portrayals        display.attach(gridPortrayal,"Life");        // specify the backdrop color  -- what gets painted behind the displays        display.setBackdrop(Color.black);        }    public static void main(String[] args)        {        Tutorial2 tutorial2 = new Tutorial2();        Console c = new Console(tutorial2);        c.setVisible(true);        }        public void load(SimState state)        {        super.load(state);        setupPortrayals();  // we now have new grids.  Set up the portrayals to reflect this        display.reset();    // reschedule the displayer        display.repaint();  // redraw the display        }            }                    

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?