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

📄 select.java

📁 这个是朋友作的毕业设计
💻 JAVA
字号:
package Resource_Selection;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import com.borland.dx.sql.dataset.*;

public class select extends JFrame {
  JPanel contentPane;
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JTextField jTextField2 = new JTextField();
  JTextField jTextField3 = new JTextField();
  JTextField jTextField5 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  classad classad = new classad();
  static classad que[];
  static int process_no=1,cpu=0,max,contra1=0,contra2=0;
  static int a[][]=new int[20][20];
  static int output_no;
  int b[]=new int[10];
  JComboBox jComboBox1 = new JComboBox();
  JButton jButton3 = new JButton();

  //Construct the frame
  public select() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  //Component initialization
  private void jbInit() throws Exception  {
    contentPane = (JPanel) this.getContentPane();
    jLabel1.setText("CPU需求");
    jLabel1.setBounds(new Rectangle(8, 41, 101, 18));
    contentPane.setLayout(null);
    this.setSize(new Dimension(400, 333));
    this.setTitle("预选");
    jLabel2.setText("内存需求");
    jLabel2.setBounds(new Rectangle(9, 69, 97, 23));
    jLabel3.setText("硬盘需求");
    jLabel3.setBounds(new Rectangle(8, 98, 98, 22));
    jLabel4.setText("操作系统");
    jLabel4.setBounds(new Rectangle(10, 125, 92, 24));
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(118, 39, 107, 22));
    jTextField2.setText("");
    jTextField2.setBounds(new Rectangle(118, 69, 107, 22));
    jTextField3.setText("");
    jTextField3.setBounds(new Rectangle(118, 97, 106, 22));
    jButton1.setBounds(new Rectangle(9, 190, 121, 26));
    jButton1.setText("提交并进行预选");
    jButton1.addActionListener(new select_jButton1_actionAdapter(this));
    jButton2.setBounds(new Rectangle(8, 225, 123, 24));
    jButton2.setText("返回");
    jButton2.addActionListener(new select_jButton2_actionAdapter(this));
    contentPane.setPreferredSize(new Dimension(1, 1));
    contentPane.setToolTipText("");
    contentPane.setVerifyInputWhenFocusTarget(true);
    jTextField5.setText("");
    jTextField5.setBounds(new Rectangle(116, 154, 109, 24));
    jLabel5.setText("进程分段数目");
    jLabel5.setBounds(new Rectangle(10, 154, 95, 24));
    jComboBox1.setToolTipText("");
    jComboBox1.setSelectedIndex(-1);
    jComboBox1.addItem("windows");
    jComboBox1.addItem("linux");
    jComboBox1.addItem("unix");
    jComboBox1.setBounds(new Rectangle(117, 124, 108, 24));
    jButton3.setBounds(new Rectangle(7, 258, 123, 27));
    jButton3.setText("清空");
    jButton3.addActionListener(new select_jButton3_actionAdapter(this));
    contentPane.add(jLabel1, null);
    contentPane.add(jLabel3, null);
    contentPane.add(jTextField2, null);
    contentPane.add(jTextField3, null);
    contentPane.add(jTextField1, null);
    contentPane.add(jButton1, null);
    contentPane.add(jButton2, null);
    contentPane.add(jTextField5, null);
    contentPane.add(jLabel4, null);
    contentPane.add(jLabel2, null);
    contentPane.add(jLabel5, null);
    contentPane.add(jComboBox1, null);
    contentPane.add(jButton3, null);

//初始化结构
    que = new classad[20];
    for(int i=0;i<que.length;i++){
    que[i] = new classad();
    }
  }
  //Overridden so we can exit when window is closed
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
       this.dispose();
    }
  }

  void jButton1_actionPerformed(ActionEvent e) {
  String sql = null;
  String system[]=new String[3];
  system[0]="windows";
  system[1]="linux";
  system[2]="unix";
  int table_1=0,table_2=0,table_3=0,table_4=0;
  if(jTextField1.getText()!=null){
    table_1 = Integer.parseInt(jTextField1.getText());
  }else if(jTextField1.getText()==null){
    table_1 = 0;
  }
  if(jTextField2.getText()!=null){
    table_2 = Integer.parseInt(jTextField2.getText());
  }else if(jTextField2.getText()==null){
    table_2 = 0;
  }
  if(jTextField3.getText()!=null){
    table_3 = Integer.parseInt(jTextField3.getText());
  }else if(jTextField3.getText()==null){
    table_3 = 0;
  }
  table_4 = jComboBox1.getSelectedIndex();
  if(jTextField5.getText()!=null&&Integer.parseInt(jTextField5.getText())!=0){
    process_no = Integer.parseInt(jTextField5.getText());
  String command="select * from computer where 主频 > " + Integer.toString(table_1) + "and 内存 >" + Integer.toString(table_2) + "and 硬盘 >" + Integer.toString(table_3) + "and 操作系统 = '" + system[table_4] + "'and 是否开放 = 'y'";
//  String command="select * from computer where 主频 > " + Integer.toString(table_1) + "and 内存 >" + Integer.toString(table_2) + "and 硬盘 >" + Integer.toString(table_3) +  "and 是否开放 = 'y'";
  String command1="";
  //sql = "insert into computer (cpu,memory,disk,system) values ('" + table_1 + "'," + Integer.toString(table_2) + "," + Integer.toString(table_3) + ",'" + table_4 + "')";
  max=Resource_Selection.user.contra;
  que_in(command,table_1,que);
  a_start(a,contra2,contra2);
  int i=0;
//  rank rank1=new rank();
  que_change(1,que,contra2);
//查看运算前后变量变化用
//  jTextField2.setText("[0]"+Integer.toString(a[i][0])+",[1]"+Integer.toString(a[i][1])+",[2]"+Integer.toString(a[i][2])+",[3]"+Integer.toString(a[i][3])+",[4]"+Integer.toString(a[i][4]));
//  int lv=rank1.rank(a,2,que,contra2);
//  jTextField1.setText(Integer.toString(contra2)+",cpu"+Integer.toString(max));
//  jTextField2.setText(Integer.toString(que[0].no)+",cpu"+Integer.toString(que[1].no)+",cpu"+Integer.toString(que[2].no)+",cpu"+Integer.toString(que[3].no)+",cpu"+Integer.toString(que[4].no)+",cpu"+Integer.toString(que[5].no));
//  jTextField3.setText(Integer.toString(que[0].cpu)+",cpu"+Integer.toString(que[1].cpu)+",cpu"+Integer.toString(que[2].no)+",cpu"+Integer.toString(que[3].cpu)+",cpu"+Integer.toString(que[4].cpu)+",cpu"+Integer.toString(que[5].cpu));
//  jTextField3.setText("a[2][0]"+Integer.toString(a[2][0])+",a[2][1]"+Integer.toString(a[2][1])+",a[2][2]"+Integer.toString(a[2][2])+",a[2][3]"+Integer.toString(a[2][3])+",a[2][4]"+Integer.toString(a[2][4]));
//  jTextField4.setText(Integer.toString(Resource_Selection.rank.se[0])+",cpu"+Integer.toString(Resource_Selection.rank.se[1])+",cpu"+Integer.toString(Resource_Selection.rank.se[2])+",cpu"+Integer.toString(Resource_Selection.rank.se[3])+",cpu"+Integer.toString(Resource_Selection.rank.se[4]));
//  resource_across resource_across = new resource_across();
//  resource_across.resource_across(a, contra2, contra2, que);
  resource_selections(a,contra2,contra2,que);
//  jTextField3.setText("[0]"+Integer.toString(a[i][0])+",[1]"+Integer.toString(a[i][1])+",[2]"+Integer.toString(a[i][2])+",[3]"+Integer.toString(a[i][3])+",[4]"+Integer.toString(a[i][4]));
  output_no=max_rank(contra2,contra2,a,que);
//  jTextField5.setText(Integer.toString(output_no));
//  jTextField1.setText(Integer.toString(b[0])+Integer.toString(b[1])+Integer.toString(b[2])+Integer.toString(b[3]));
//  jTextField5.setText(Integer.toString(rank.rank(a,0,que,contra2))+"rank"+Integer.toString(rank.rank(a,1,que,contra2))+"rank"+Integer.toString(rank.rank(a,2,que,contra2))+",cpu"+Integer.toString(Resource_Selection.rank.classad.cpu));
  new output_app();
  }else if(jTextField5.getText()==null||Integer.parseInt(jTextField5.getText())==0){
   new err_process();
 }
}


  void jButton2_actionPerformed(ActionEvent e) {
      //System.exit(0);
      this.dispose();
  }

  public void que_in(String command,int table_1,classad a[]){
    String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
    String connectionURL = "jdbc:odbc:computer";//driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\WINDOWS\\Desktop\\desktop\\毕业设计\\Grid\\computer.mdb";
    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;
    String adm = null;
    contra2=0;
//    contra1=0;
    try {
       Class.forName(driverName).newInstance();
       con = DriverManager.getConnection(connectionURL);
       stmt = con.createStatement();
//            command1="select cpu from computer where no =" + Integer.toString(contra1);
         rs = stmt.executeQuery(command);
        while(rs.next()){
          cpu = Integer.parseInt(rs.getString("主频"));
         if(cpu > table_1){
           a[contra2].no = Integer.parseInt(rs.getString("编号"));
           a[contra2].cpu = cpu;
           a[contra2].netspeed = Integer.parseInt(rs.getString("网络速度"));
           a[contra2].ip = rs.getString("地址");
           contra2++;
         }
        }
       }
       catch(Exception ex)
     {
       ex.printStackTrace();
     }
    finally {
         try {
           rs.close();
           stmt.close();
           con.close();
         }
         catch (Exception ex) {
           ex.printStackTrace();
         }
     }
  }
  public void a_start(int a[][],int m,int n){
      Random rd=new Random();
      int i,j;
      int rdget = Math.abs(rd.nextInt()) % m;
      for(i=0;i<m;i++){
        for (j = 0; j < n; j++) {
          a[i][j] = Math.abs(rd.nextInt()) % 2;
        }
      }
      for(j=0;j<n;j++){
          a[0][j]=1;//Math.abs(rd.nextInt()) % 2;
        }
  }
  public void que_change(int i,classad a[],int m){
    int j,s,no;
    String ip;
    switch (i)
      {
      case 1:
        for(j=0;j<m;j++){
          for(s=0;s<m;s++){
            if(a[s].no>a[j].no){
              no = a[s].no;
              a[s].no = a[j].no;
              a[j].no = no;
              no = a[s].cpu;
              a[s].cpu = a[j].cpu;
              a[j].cpu = no;
              no = a[s].netspeed;
              a[s].netspeed = a[j].netspeed;
              a[j].netspeed = no;
              ip = a[s].ip;
              a[s].ip = a[j].ip;
              a[j].ip = ip;
            }
          }
        }
      }
  }
  void resource_selections(int a[][],int m,int n,classad que[])
  { int i=0,j=0,s,e;
    int temp_stop[][]=new int[20][20];
    resource_across resource_across = new resource_across();
    resource_select resource_select = new resource_select();
    resource_variation resource_variation = new resource_variation();
    Random rd = new Random();
    int rdget;
    jindu jindu=new jindu();
    while(j < m * n * m * n * m){
      i=0;
      while (i < m) {
        for (s = 0; s < m; s++) {
          for (e = 0; e < n; e++) {
            temp_stop[s][e] = a[s][e];
          }
        }
        rdget = Math.abs(rd.nextInt()) % 3;
        switch (rdget) {
          case 0:
            resource_across.resource_across(a, m, n, que);
          case 1:
            resource_select.resource_select(a, m, n, que);
          case 2:
            resource_variation.resource_variation(a, m, n, que);
        }
        i++;
      }
//     if (stop_select(a, m, n, temp_stop) > 97){
//           j=m*n*m*n*m*n;}
      j++;
      jindu.frame.set_p(j*100/(m*m*m*n*n));
    }
    jindu.frame.jindu_close();
  }
  public int stop_select(int a[][],int m,int n,int temp[][])
  {
    int  stop=0,up=0,i,j;
    for(i=0;i<m;i++)
    {
      for(j=0;j<n;j++) {
        if(temp[m][n] == a[m][n])
           up++;
      }
    }
    stop=up/(m*n)*100;
    return stop;
  }
  int max_rank(int m,int n,int a[][],classad que[])
  {
    rank rank=new rank();
    int i=0,max = rank.rank(a, 0, que, n), max_no = 0, c=0;
    while (i < m) {
      c = rank.rank(a, i, que, n);
      b[i]=c;
      if (c > max) {
        max = c;
        max_no = i;
      }
      i++;
    }
    return max_no;
  }

  void jButton3_actionPerformed(ActionEvent e) {
    jTextField1.setText("");
    jTextField2.setText("");
    jTextField3.setText("");
    jComboBox1.setSelectedIndex(0);
    jTextField5.setText("");
  }
}
class select_jButton2_actionAdapter implements java.awt.event.ActionListener {
  select adaptee;

  select_jButton2_actionAdapter(select adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class select_jButton1_actionAdapter implements java.awt.event.ActionListener {
  select adaptee;

  select_jButton1_actionAdapter(select adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class select_jButton3_actionAdapter implements java.awt.event.ActionListener {
  select adaptee;

  select_jButton3_actionAdapter(select adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton3_actionPerformed(e);
  }
}

⌨️ 快捷键说明

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