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

📄 ant pathapp.java

📁 蚂蚁算法的java实现,主要在选择路径的迭代上做了改进
💻 JAVA
字号:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import SimFrameWork.*;

public class AntApp extends JFrame{
  public AntApp(){
    super("Ant Foraging Simulation");
    try{jbInit();}
    catch(Exception e){e.printStackTrace();}
  }
  private void jbInit() throws Exception{
    getContentPane().setLayout(new BorderLayout());
    displayPanel=new JPanel();
    displayPanel.setPreferredSize(new Dimension(WIDTH*BLOCKSIZE,HEIGHT*BLOCKSIZE));
    getContentPane().add("Center",displayPanel);
    JPanel statusPanel=new JPanel(new BorderLayout());
    statusPanel.setBorder(BorderFactory.createLoweredBevelBorder());
    getContentPane().add("South",statusPanel);
    statusLabel=new JLabel();
    statusPanel.add(statusLabel);
    addWindowListener(new WindowAdapter(){
      public void windowClosing(WindowEvent e){
        System.exit(0);
      }
    });
    pack();
    setVisible(true);
  }
  public void runSimulation(){
    AntDisplay display=new AntDisplay(WIDTH,HEIGHT,BLOCKSIZE,displayPanel);
    AntWorld world=new AntWorld(WIDTH,HEIGHT,display);
    control=new MainLoop(world);
    control.start();
    status=new AntStatus(world,statusLabel);
    status.start();
  }
  public void stopSimulation(){
    status.stopControl();
    control.stopControl();
  }
  public static void main(String args[]){
    AntApp app=new AntApp();
    app.runSimulation();
  }
  private MainLoop control;
  private AntStatus status;
  private JPanel displayPanel;
  private JLabel statusLabel;
  private final int WIDTH=100;
  private final int HEIGHT=100;
  private final int BLOCKSIZE=8;
}

⌨️ 快捷键说明

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