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

📄 fuzzy_control_frame.java

📁 分别是模糊识别、模糊聚类、模糊控制的实例代码
💻 JAVA
字号:
package fuzzy_control;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.ImageIcon;
import java.awt.event.*;

public class Fuzzy_control_Frame extends JFrame implements Runnable{
  JPanel contentPane;
  BorderLayout borderLayout1 = new BorderLayout();
  Image bugimag1,bugimag2,bugimag3,backimage;
  Map_manager mm;
  byte[][] map;
  int width,height;
  static int px,py;
  Fuzzy_controller fc;
  matrix_com mc;
  Input in;
  Output out;
  Distance_detect dd;
  private double distance[][]={
      {1,0.6,0.2,0,0,0,0},
      {0.6,1,0.6,0.2,0,0,0},
      {0.2,0.6,1,0.6,0.2,0,0},
      {0,0.2,0.6,1,0.6,0.2,0},
      {0,0,0.2,0.6,1,0.6,0.2},
      {0,0,0,0.2,0.6,1,0.6},
      {0,0,0,0,0.2,0.6,1},
  };
  private double direction[][]={
      {1,0.6,0.2,0,0,0,0,0,0,0,0},
      {0.6,1,0.6,0.2,0,0,0,0,0,0,0},
      {0,0.2,0.6,1,0.6,0.2,0,0,0,0,0},
      {0,0,0,0.2,0.6,1,0.6,0.2,0,0,0},
      {0,0,0,0,0,0.2,0.6,1,0.6,0.2,0},
      {0,0,0,0,0,0,0,0.2,0.6,1,0.6},
      {0,0,0,0,0,0,0,0,0.2,0.6,1},
  };
  private static double Fuzzy_strategy[][];
  private double Input_Matrix[][];
  private double Output_Matrix[][];
  private int Ang;
  private int count;

  //Construct the frame
  public Fuzzy_control_Frame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
      Thread t=new Thread(this);
      t.start();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("机器虫模糊控制");
    bugimag1 = loadImage("images/fly1.png");
    bugimag2 = loadImage("images/fly2.png");
    bugimag3 = loadImage("images/fly3.png");
    backimage = loadImage("images/background.jpg");
    height = 300;
    width = 400;
    mm=new Map_manager(height,width);
    map=mm.returnMap();
    px=299;
    py=200;
    fc=new Fuzzy_controller(distance,direction);
    Fuzzy_strategy=fc.Get_strategy();
    mc=new matrix_com();
    in=new Input(distance);
    out=new Output();
    dd=new Distance_detect(map);
    count=1;
  }

  public void run()
  {
    for(int i=0;i<16;i++)
    {
      Input_Matrix=in.Input_Fuzzy(dd.distance(px,py));
      Output_Matrix=mc.exe(Input_Matrix,Fuzzy_strategy,1,7,11);
      out.Output_ang(Output_Matrix,px,py);
      px=out.Get_px();
      py=out.Get_py();
      repaint();
      try
      {
        Thread.sleep(500);
      }catch(InterruptedException e){};
    }
  }

  private Image loadImage(String fileName)
  {
      return new ImageIcon(fileName).getImage();
  }

  public void update(Graphics g)
  {
    paint(g);
  }

  public void paint(Graphics g) {
   g.drawImage(backimage,0,0,null);
   if(count==4)
   {
     count=1;
   }
   if(count==1)
   {
     g.drawImage(bugimag1,py-30,px,60,40,null);
   }
   if(count==2)
   {
     g.drawImage(bugimag2,py-30,px,60,40,null);
   }
   if(count==3)
   {
     g.drawImage(bugimag3,py-30,px,60,40,null);
   }
   count++;
   px=px-10;
}
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }
}

⌨️ 快捷键说明

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