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

📄 resultframe.java~12~

📁 基于java实现的遗传算法 神经网络 实数编码 交叉 选择 变异
💻 JAVA~12~
字号:
package ga;

import com.borland.jbcl.layout.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;


/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class ResultFrame extends JFrame {

  public ResultFrame(double actualResult[], double sampleResult[], LinkedList[] info,double max,double min) {
    this.actualResult = actualResult;
    this.sampleResult = sampleResult;
    this.info = info;
    this.maxOut=max;
    this.minOut=min;
    try{
      jbInit();
      //display();
    }
    catch (Exception e){}
    this.addWindowListener(new WindowAdapter(){
       public void WindowClosing(WindowEvent e){
         System.exit(0);
       }
    });
  }

  public void displayFunction()
  {
    int size = actualResult.length;
    int xInterval = 833 / (size + 2); //size / 1;///500
    int x,y;
    double yd;
    int width;
    String str;
    if (bufferedImage == null)
      bufferedImage = createImage(780, 460);
    Graphics bg = bufferedImage.getGraphics();
    Graphics g = jPanel2.getGraphics();
    bg.setColor(bgColor);
    bg.fillRect(0, 0, 780, 460);

    bg.setColor(actualColor);

    bg.drawString("actual Result --- Red",25,440);
    bg.drawString("sample Result --- blue",25,420);

    FontMetrics fm = bg.getFontMetrics(targetFont);
    x =  25; // xInterval;
    yd = 460.0 -
          (actualResult[0] -minOut) * 420.0 / (maxOut - minOut) - 20.0;

    y = (int)yd;
    bg.fillOval(x,y,5,5);
    str =   df.format(actualResult[0]) + "";
    width = fm.stringWidth(str);
    bg.drawString(str, x - width / 2, y - 5);

    Point lastp = new Point(x,y);
    Point p;

    for (int index = 1; index < size; index++) {//从1开始
      x = index * xInterval + 25; // xInterval;
      yd = 460.0 -
          (actualResult[index] - minOut) * 420.0 / (maxOut - minOut) - 20.0;
      y = (int)yd;

      p = new Point(x,y);

      //bg.drawLine(x, 460, x, y);
      bg.fillOval(x,y,5,5);
      bg.drawLine(lastp.x, lastp.y, p.x, p.y);
      lastp = p;
      str = df.format(actualResult[index]) + "";
      width = fm.stringWidth(str);
      bg.drawString(str, x - width / 2, y - 5);
    }


    //draw actual Result
    bg.setColor(sampleColor);
    x =  25; // xInterval;
    yd = 460.0 -
          (sampleResult[0] - minOut) * 420.0 / (maxOut - minOut) - 20.0;
    y = (int)yd;
    bg.fillOval(x,y,5,5);
    str =  df.format(sampleResult[0]) + "";
    width = fm.stringWidth(str);
    bg.drawString(str, x - width / 2, y - 5);

    lastp = new Point(x,y);

    for (int index = 1; index < size; index++) {//从1开始
      x = index * xInterval + 25; // xInterval;
      yd = 460.0 -
          (sampleResult[index] - minOut) * 420.0 / (maxOut - minOut) - 20.0;
      y = (int)yd;

      p = new Point(x,y);

      //bg.drawLine(x, 460, x, y);
      bg.fillOval(x,y,5,5);
      bg.drawLine(lastp.x, lastp.y, p.x, p.y);
      lastp = p;
      str = df.format(sampleResult[index]) + "";
      width = fm.stringWidth(str);
      bg.drawString(str, x - width / 2, y - 5);
    }



    bg.dispose();
    //g.drawImage(bufferedImage, 25, 142, null);]
    g.drawImage(bufferedImage,0,0,null);
  }

  public void displayWeight(){
    int x,y;
   double yd;
   int width;
   String str;
   ListIterator I;
   if (bufferedImage == null)
     bufferedImage = createImage(780, 460);
   Graphics bg = bufferedImage.getGraphics();
   Graphics g = jPanel2.getGraphics();
   bg.setColor(bgColor);
   bg.fillRect(0, 0, 780, 460);
   bg.setColor(Color.black);
   bg.drawString("weighti[0][0] -- Red  weighth[0][0][1] -- Green  weighth[0][1][2]"
                   + " -- Blue  weighth[0][2][0] -- Magenta  weighto[0][2] -- Cyan",25,450);
  FontMetrics fm = bg.getFontMetrics(targetFont);
 int xInterval = 833 / (info[0].size() + 2); //size / 1;///500
 System.out.println(info[0]); //shanchu
 System.out.println(xInterval);

 double d;
  int index;
  double min;
  double max;

//循环遍历链表
    for(int i = 0; i < info.length; i++){

   I = info[i].listIterator();


   bg.setColor(infoColors[i]);
   min = ((Double)I.next()).doubleValue();
   max = ((Double)I.next()).doubleValue();
   index = 0;
   x =  25; // xInterval;
   d = ((Double)(I.next())).doubleValue();
   yd = 460.0 -
         (d - (min)) * 420.0 / (max - (min)) - 20.0;
   y = (int)yd;
   bg.fillOval(x,y,5,5);
   str =   df1.format(d) + "";
   width = fm.stringWidth(str);
   bg.drawString(str, x - width / 2, y - 5);

   Point lastp = new Point(x,y);
   Point p;
   index++;

   while(I.hasNext()){//从1开始
     d = ((Double)(I.next())).doubleValue();
    // System.out.print(d);
     x = index * xInterval + 25; // xInterval;
     yd = 460.0 -
         (d - (min)) * 420.0 / (max - (min)) - 20.0;
     y = (int)yd;

     p = new Point(x,y);

     //bg.drawLine(x, 460, x, y);
     bg.fillOval(x,y,5,5);
     bg.drawLine(lastp.x, lastp.y, p.x, p.y);
     lastp = p;
     str = df1.format(d) + "";
     width = fm.stringWidth(str);
     bg.drawString(str, x - width / 2, y - 5);
     index++;
   }

 }//end for

   bg.dispose();
   //g.drawImage(bufferedImage, 25, 142, null);]
   g.drawImage(bufferedImage,0,0,null);


  }

  private class SortPanel extends JPanel
    {
     public void paintComponent(Graphics g)
     {
       super.paintComponent(g);
       //display();
     }
    }


  private void jbInit() throws Exception {
    this.getContentPane().setLayout(xYLayout1);
    jPanel1.setLayout(xYLayout2);
    jPanel1.setBackground(bgColor);
    jPanel2.setBackground(bgColor);
    jPanel2.setLayout(xYLayout3);
    jBtnOK.setText("OK");
   // jBtnOK.addActionListener(new java.awt.event.ActionListener() {
    //  public void actionPerformed(ActionEvent e) {
    //    jBtnOK_actionPerformed(e);
    //  }
   // }
//);
    xYLayout1.setWidth(852);
    xYLayout1.setHeight(682);

    //sortKind.addActionListener(this);

    //sortMethod.addActionListener(this);


    functionBtn.setText("view function");
    functionBtn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        displayFunction();
      }
    }
);
    weightBtn.setActionCommand("jButton2");
    weightBtn.setText("view weight");
   weightBtn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
       displayWeight();
      }
  }
     // }
);
    //searchBtn.addActionListener(new java.awt.event.ActionListener() {
    //  public void actionPerformed(ActionEvent e) {
     //   searchBtn_actionPerformed(e);
  //  }
//);

    this.getContentPane().add(jPanel1,       new XYConstraints(11, 11, 828, 95));
    this.getContentPane().add(jPanel2,     new XYConstraints(4, 120, 833, 482));
    this.getContentPane().add(jBtnOK,  new XYConstraints(383, 611, -1, -1));
    jPanel1.add(weightBtn,  new XYConstraints(635, 43, -1, -1));
    jPanel1.add(functionBtn, new XYConstraints(163, 41, -1, -1));
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setSize(d.width/3*2 + 20,d.height/3*2 + 60);

  }

  //private section
   //instance fields

   XYLayout xYLayout1 = new XYLayout();
  JPanel jPanel1 = new JPanel();
  XYLayout xYLayout2 = new XYLayout();
  SortPanel jPanel2 = new SortPanel();
  JButton jBtnOK = new JButton();


  private boolean ok;
   XYLayout xYLayout3 = new XYLayout();
   JButton functionBtn = new JButton();
   JButton weightBtn = new JButton();
      private Image bufferedImage;
      public boolean display;

      public static int MAX_KEYNUM;
      private static int MAX_LENGTH = 30;
      private static int MAX_DIGIT = 999;

      private Color bgColor = new Color(255,255,192);
      private Color actualColor = new Color(255,0,0);
      private Color sampleColor = new Color(0,0,255);

      private Color[] infoColors = { Color.red,Color.green,
      Color.blue,Color.magenta,Color.cyan
      };

     Font targetFont = new Font("SansSerif",Font.BOLD,12);

     private boolean isStepSortFinished = false;

private DecimalFormat df = new DecimalFormat("0.###");
private DecimalFormat df1 = new DecimalFormat("0.##");

private double actualResult[];
private double sampleResult[];

private double minOut;
private double maxOut;
private LinkedList[] info;



}

⌨️ 快捷键说明

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