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

📄 matrix.java

📁 本软件是使用java 开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    tPromptCol.setBackground(Color.yellow);
    tPromptCol.setAlignment(Label.CENTER);
    centerPanel.add(tPromptCol);

    tPromptData = new Label("T 数据");
    tPromptData.setSize(40, 25);
    tPromptData.setLocation(20, 300);
    tPromptData.setBackground(Color.blue);
    tPromptData.setAlignment(Label.CENTER);
    centerPanel.add(tPromptData);

    colprompt = new Label("列");
    colprompt.setSize(40, 25);
    colprompt.setLocation(20, 350);
    colprompt.setBackground(Color.green);
    colprompt.setAlignment(Label.CENTER);
    centerPanel.add(colprompt);

    numPrompt = new Label("num[col]");
    numPrompt.setSize(40, 25);
    numPrompt.setLocation(20, 375);
    numPrompt.setBackground(Color.cyan);
    numPrompt.setAlignment(Label.CENTER);
    centerPanel.add(numPrompt);

    coltPrompt = new Label("colt[col]");
    coltPrompt.setSize(40, 25);
    coltPrompt.setLocation(20, 400);
    coltPrompt.setBackground(Color.magenta);
    coltPrompt.setAlignment(Label.CENTER);
    centerPanel.add(coltPrompt);

    for (int i = 1; i <= M.nu; i++) {
      colLabel = new Label[M.nu + 1];
      colLabel[i] = new Label(String.valueOf(i));
      colLabel[i].setSize(40, 25);
      colLabel[i].setLocation(20 + 42 * i, 350);
      colLabel[i].setBackground(Color.green);
      colLabel[i].setAlignment(Label.CENTER);
      centerPanel.add(colLabel[i]);

      Label numPrompt = new Label("num[col]");
      numPrompt.setSize(40, 25);
      numPrompt.setLocation(20, 375);
      numPrompt.setBackground(Color.cyan);
      numPrompt.setAlignment(Label.CENTER);
      centerPanel.add(numPrompt);
      numLabel[i] = new Label(String.valueOf( (int) (Math.random() * 100)));
      numLabel[i].setSize(40, 25);
      numLabel[i].setLocation(20 + 42 * i, 375);
      numLabel[i].setBackground(Color.cyan);
      numLabel[i].setAlignment(Label.CENTER);
      centerPanel.add(numLabel[i]);
      coltLabel[i] = new Label(String.valueOf( (int) (Math.random() * 100)));
      coltLabel[i].setSize(40, 25);
      coltLabel[i].setLocation(20 + 42 * i, 400);
      coltLabel[i].setBackground(Color.magenta);
      coltLabel[i].setAlignment(Label.CENTER);
      centerPanel.add(coltLabel[i]);
    }
  }

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

  public void actionPerformed(ActionEvent actionevent) {

    if (actionevent.getSource() == newButton) {
      stop();
      this.textfield22.setText("");
      this.textfield32.setText("");
      this.textfield42.setText("");
      this.textfield52.setText("");
      MatrixFrame.matrixdia.setSize(500, 400);
      MatrixFrame.matrixdia.setVisible(true);
      M = MatrixFrame.matrixdia.getTsmatrix();
      centerPanel.removeAll();
      drawMode = 1;
      stepButton.setEnabled(true);
      runButton.setEnabled(true);
      stayButton.setEnabled(true);
      doneFlag = false;
    }
    if (actionevent.getSource() == stepButton) {
      runFlag = false;
      if (doneFlag) {
        newButton.setEnabled(true);
        runButton.setEnabled(false);
        stepButton.setEnabled(false);
        stayButton.setEnabled(false);
        runFlag = false;
        JOptionPane.showConfirmDialog(this,
                                      "    算法演示完成!\n  \n 单击相关按钮重新开始\n",
                                      "演示完成", JOptionPane.DEFAULT_OPTION);

      }
      this.matixStep();
      dataupdate();
    }
    if (actionevent.getSource() == runButton) {
      doneFlag = false;
      runFlag = true;
      this.start();
    }
    if (actionevent.getSource() == stayButton) {
      runFlag = false;
    }

    repaint();
  }

  public void dataupdate() { //更新显示变量
    this.textfield22.setText(String.valueOf(col));
    this.textfield32.setText(String.valueOf(q));
    this.textfield42.setText(String.valueOf(p));
    this.textfield52.setText(String.valueOf(cpot[col]));
  }

  public void run() {
    while (Thread.currentThread() == this.runner) {

      if (runFlag) {
        if (doneFlag) { //判断是否运行结束
          newButton.setEnabled(true);
          runButton.setEnabled(false);
          stepButton.setEnabled(false);
          stayButton.setEnabled(false);
          runFlag = false;
          JOptionPane.showConfirmDialog(this,
                                        "    算法演示完成!\n  \n 单击相关按钮重新开始\n",
                                        "演示完成", JOptionPane.DEFAULT_OPTION);

          this.stop();
        }
        this.matixStep();
        dataupdate();
        repaint();
        try {
          controls = controlsPanel.delay;
          if (controls <= 50)
            controls = 50;
          Thread.sleep(controls);
        }
        catch (Exception e) {}
      }
    }
  }

  public void matixStep() {
    switch (codePart) {
      case 1:
        col = 1;
        t = 1;
        p = 1;
        movePos = p;
        codePart = 3;
        codePanel.highlight(1);
        drawMode = 4;
        return;
      case 3:
        int trow = M.nu;
        int tcol = M.mu;
        int ttu = M.tu;

        T = new TSMatrix(trow, tcol, ttu);
        codePanel.highlight(3);
        codePart = 4;
        drawMode = 4;
        return;
      case 4:
        if (T.tu <= 0) {
          codePart = 19;
        }
        else {
          codePart = 5;
        }
        codePanel.highlight(4);
        return;
      case 5:
        if (col <= M.nu) {
          codePart = 6;
        }
        else {
          codePart = 7;
        }
        codePanel.highlight(5);
        return;
      case 6:
        drawMode = 2;
        num[col] = 0;
        position = col;
        col++;
        codePart = 5;
        codePanel.highlight(6);
        return;
      case 7:
        if (t <= M.tu) {
          codePart = 8;

        }
        else {
          codePart = 9;
        }
        codePanel.highlight(7);
        return;
      case 8:

        drawMode = 3;
        ++
            num[M.data[t].col];
        t++;
        codePart = 7;
        codePanel.highlight(8);
        return;
      case 9:
        drawMode = 5;
        cpot[1] = 1;
        position = 1;
        col = 2;
        codePart = 10;
        codePanel.highlight(9);
        return;
      case 10:
        if (col <= M.nu) {
          codePart = 11;
        }
        else {
          codePart = 12;
        }
        codePanel.highlight(10);
        drawMode = 4;
        return;
      case 11:
        drawMode = 5;
        cpot[col] = cpot[col - 1] + num[col - 1];
        position = col;
        col++;
        codePart = 10;
        codePanel.highlight(11);
        return;
      case 12:
        if (p <= M.tu) {
          codePart = 13;
        }
        else {
          codePart = 20;
        }
        codePanel.highlight(12);
        drawMode = 4;
        return;
      case 13:
        movePos = p;
        col = M.data[p].getCol();
        codePart = 14;
        codePanel.highlight(13);
        drawMode = 6;
        subDrawMode = 1;
        return;
      case 14:
        q = cpot[col];
        moveEnd = q;
        codePart = 15;
        codePanel.highlight(14);
        drawMode = 6; //////////////
        subDrawMode = 2;
        return;
      case 15:
        T.data[q].row = M.data[p].col;
        codePart = 16;
        codePanel.highlight(15);
        drawMode = 6; //////////////
        subDrawMode = 3;
        return;
      case 16:
        T.data[q].col = M.data[p].row;
        codePart = 17;
        codePanel.highlight(16);
        drawMode = 6; //////////////
        subDrawMode = 4;
        return;
      case 17:
        T.data[q].data = M.data[p].data;
        codePart = 18;
        codePanel.highlight(17);
        drawMode = 6; //////////////
        subDrawMode = 5;
        return;
      case 18:
        ++
            cpot[col];
        codePart = 12;
        codePanel.highlight(18);
        ++
            p;
        drawMode = 6; //////////////
        subDrawMode = 6;
        return;
      case 20:
        doneFlag = true;
        runFlag = true;
        codePanel.highlight(19);
        drawMode = 1;
        subDrawMode = 1;
        codePart = 1;
        return;
    }
  }

  public Matrix() {
    this.init();
  }

}

⌨️ 快捷键说明

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