⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bigparticleinspector.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.tutorial4;import sim.portrayal.*;import sim.portrayal.grid.*;import sim.field.grid.*;import java.awt.event.*;import java.awt.*;import javax.swing.*;import sim.engine.*;import sim.util.*;import sim.display.*;public class BigParticleInspector extends Inspector    {    public Inspector originalInspector;        public BigParticleInspector(Inspector originalInspector,                                LocationWrapper wrapper,                                GUIState guiState)        {        this.originalInspector = originalInspector;                // get info out of the wrapper        SparseGridPortrayal2D gridportrayal = (SparseGridPortrayal2D) wrapper.getFieldPortrayal();        // these are final so that we can use them in the anonymous inner class below...        final SparseGrid2D grid = (SparseGrid2D)(gridportrayal.getField());        final BigParticle particle = (BigParticle) wrapper.getObject();        final SimState state = guiState.state;        final Controller console = guiState.controller;  // The Console (it's a Controller subclass)                // now let's add a Button        Box box = new Box(BoxLayout.X_AXIS);        JButton button = new JButton("Roll the Dice");        box.add(button);        box.add(Box.createGlue());        // set up our inspector: keep the properties inspector around too        setLayout(new BorderLayout());        add(originalInspector, BorderLayout.CENTER);        add(box, BorderLayout.NORTH);                // set what the button does        button.addActionListener(new ActionListener()            {            public void actionPerformed(ActionEvent e)                {                synchronized(state.schedule)                    {                    // randomize direction                    particle.xdir = state.random.nextInt(3) - 1;                    particle.ydir = state.random.nextInt(3) - 1;                                        // randomize location                    grid.setObjectLocation(particle,                                           new Int2D(state.random.nextInt(grid.getWidth()),                                                     state.random.nextInt(grid.getHeight())));                                        // repaint everything: console, inspectors, displays,                    // everything that might be affected by randomization                    console.refresh();                    }                }            });        }            public void updateInspector()        {        originalInspector.updateInspector();        }    }

⌨️ 快捷键说明

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