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

📄 antsforagewithui.java

📁 MASON代表多主体邻里或网络仿真(Multi-Agent Simulator of Neighborhoods or Networks)。它是乔治梅森大学用Java开发的离散事件多主体仿真核心库
💻 JAVA
字号:
package sim.app.antsforage;import sim.engine.*;import sim.display.*;import sim.portrayal.grid.*;import java.awt.*;import javax.swing.*;public class AntsForageWithUI extends GUIState    {    public Display2D display;    public JFrame displayFrame;    FastValueGridPortrayal2D homePheremonePortrayal = new FastValueGridPortrayal2D("Home Pheremone");    FastValueGridPortrayal2D foodPheremonePortrayal = new FastValueGridPortrayal2D("Food Pheremone");    FastValueGridPortrayal2D sitesPortrayal = new FastValueGridPortrayal2D("Site", true);  // immutable    FastValueGridPortrayal2D obstaclesPortrayal = new FastValueGridPortrayal2D("Obstacle", true);  // immutable    SparseGridPortrayal2D bugPortrayal = new SparseGridPortrayal2D();                    public static void main(String[] args)        {        AntsForageWithUI antsForage = new AntsForageWithUI();        Console c = new Console(antsForage);        c.setVisible(true);        }        public AntsForageWithUI() { super(new AntsForage(System.currentTimeMillis())); }    public AntsForageWithUI(SimState state) { super(state); }        public String getName() { return "Foraging Ants"; }        public void setupPortrayals()        {        AntsForage af = (AntsForage)state;        // tell the portrayals what to portray and how to portray them        homePheremonePortrayal.setField(af.toHomeGrid);        homePheremonePortrayal.setMap(new sim.util.gui.SimpleColorMap(                                          AntsForage.MIN_PHEROMONE,                                          AntsForage.MAX_PHEROMONE,                                          // home pheromones are beneath all, just make them opaque                                          Color.white, //new Color(0,255,0,0),                                          new Color(0,255,0,255) ));        foodPheremonePortrayal.setField(af.toFoodGrid);        foodPheremonePortrayal.setMap(new sim.util.gui.SimpleColorMap(                                          AntsForage.MIN_PHEROMONE,                                          AntsForage.MAX_PHEROMONE,                                          new Color(0,0,255,0),                                          new Color(0,0,255,255) ));        sitesPortrayal.setField(af.sites);        sitesPortrayal.setMap(new sim.util.gui.SimpleColorMap(                                  0,                                  1,                                  new Color(0,0,0,0),                                  new Color(255,0,0,255) ));        obstaclesPortrayal.setField(af.obstacles);        obstaclesPortrayal.setMap(new sim.util.gui.SimpleColorMap(                                      0,                                      1,                                      new Color(0,0,0,0),                                      new Color(128,64,64,255) ));        bugPortrayal.setField(af.buggrid);                    // make the ants look like cameras!        /*          bugPortrayal.setPortrayalForAll(          new sim.portrayal.simple.ImagePortrayal2D(          sim.display.Display2D.CAMERA_ICON.getImage()));        */                // reschedule the displayer        display.reset();        // redraw the display        display.repaint();        }        public void start()        {        super.start();  // set up everything but replacing the display        // set up our portrayals        setupPortrayals();        }                public void load(SimState state)        {        super.load(state);        // we now have new grids.  Set up the portrayals to reflect that        setupPortrayals();        }    public void init(Controller c)        {        super.init(c);                // Make the Display2D.  We'll have it display stuff later.        display = new Display2D(400,400,this,1); // at 400x400, we've got 4x4 per array position        displayFrame = display.createFrame();        c.registerFrame(displayFrame);   // register the frame so it appears in the "Display" list        displayFrame.setVisible(true);        // attach the portrayals from bottom to top        display.attach(homePheremonePortrayal,"Pheromones To Home");        display.attach(foodPheremonePortrayal,"Pheromones To Food");        display.attach(sitesPortrayal,"Site Locations");        display.attach(obstaclesPortrayal,"Obstacles");        display.attach(bugPortrayal,"Agents");                // specify the backdrop color  -- what gets painted behind the displays        display.setBackdrop(Color.white);        }            public void quit()        {        super.quit();                // disposing the displayFrame automatically calls quit() on the display,        // so we don't need to do so ourselves here.        if (displayFrame!=null) displayFrame.dispose();        displayFrame = null;  // let gc        display = null;       // let gc        }            }                

⌨️ 快捷键说明

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