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

📄 matrixdia.java

📁 本软件是使用java 开发的
💻 JAVA
字号:
package datastructure;

import java.awt.*;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

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

public class MatrixDia
    extends JDialog
    implements ActionListener {
  JPanel jPanel1 = new JPanel();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JPanel jPanel2 = new JPanel();
  JPanel jPanel3 = new JPanel();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  BorderLayout borderLayout1 = new BorderLayout();
  MatrixArr matrixarr;
  int array[][] = new int[12][12];
  int vertexnum;
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JLabel jLabel4 = new JLabel();
  JLabel jLabel5 = new JLabel();
  JLabel jLabel6 = new JLabel();
  JLabel jLabel7 = new JLabel();
  JLabel jLabel8 = new JLabel();
  JLabel jLabel9 = new JLabel();
  JTextField jTextField2 = new JTextField();
  int row = 6;
  int col = 6;
  public MatrixDia(Frame frame, String title, boolean modal) {
    super(frame, title, modal);
    try {
      jbInit();
      pack();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public MatrixDia() {
    this(null, "", false);
  }

  private void jbInit() throws Exception {
    this.setLocation(40, 40);
    jTextField1.addActionListener(this);
    jButton2.addActionListener(this);
    jButton3.addActionListener(this);
    jLabel1.setText("输入矩阵的行");
    jTextField1.setText("0");
    jTextField1.setColumns(5);

    jButton2.setText("确定");
    jButton3.setText("取消");
    this.jButton2.setEnabled(false);
    jPanel2.setLayout(new GridLayout(1, 3));

    jLabel2.setText("输入数据说明:");
    jLabel2.setBounds(new Rectangle(12, 0, 114, 37));
    jLabel3.setText("1.输入行、列,分别按回车键结束");
    jLabel3.setBounds(new Rectangle(8, 22, 195, 39));
    jLabel4.setText("2.输入矩阵的值");
    jLabel4.setBounds(new Rectangle(10, 55, 161, 31));
    jLabel5.setText("a.0代表相应的点没有值");
    jLabel5.setBounds(new Rectangle(19, 82, 140, 28));
    jLabel6.setText("b.按行输入矩阵");
    jLabel6.setBounds(new Rectangle(21, 111, 152, 26));
    jLabel7.setText("c.单击一按纽,输入值");
    jLabel7.setBounds(new Rectangle(22, 140, 148, 20));
    jLabel8.setText("3.按确定按钮结束输入");
    jLabel8.setBounds(new Rectangle(13, 168, 97, 21));
    jLabel9.setText("输入矩阵的列");
    jTextField2.setColumns(5);
    jTextField2.setText("0");
    jTextField2.addActionListener(this);
    this.getContentPane().add(jPanel1, BorderLayout.NORTH);
    jPanel1.add(jLabel1, null);
    jPanel1.add(jTextField1, null);
    jPanel1.add(jLabel9, null);
    jPanel1.add(jTextField2, null);
    JPanel leftpanel = new JPanel();
    leftpanel.setLayout(null);
    jPanel2.add(leftpanel);
    leftpanel.add(jLabel2, null);
    leftpanel.add(jLabel3, null);
    leftpanel.add(jLabel4, null);
    leftpanel.add(jLabel5, null);
    leftpanel.add(jLabel6, null);
    leftpanel.add(jLabel7, null);
    leftpanel.add(jLabel8, null);
    matrixarr = new MatrixArr();
    jPanel2.add(matrixarr);
    jPanel2.add(new JPanel());
    this.getContentPane().add(jPanel2, BorderLayout.CENTER);
    this.getContentPane().add(jPanel3, BorderLayout.SOUTH);
    jPanel3.add(jButton2, null);
    jPanel3.add(jButton3, null);

  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jTextField2) {

      boolean flag = false;
      try {
        row = Integer.parseInt(jTextField1.getText());
        col = Integer.parseInt(jTextField2.getText());
        if (row < 1 || row > 11 || (col < 1 || col > 11)) {
          JOptionPane.showMessageDialog(this, "请输入1到12的整正数");
          flag = true;
        }
      }
      catch (NumberFormatException exp) {
        JOptionPane.showMessageDialog(this, "请输入1到12的整正数");
        flag = true;
      }
      if (!flag) {
        matrixarr.clear();
        matrixarr.clearArray();
        matrixarr.createArray(row, col);
        this.jButton2.setEnabled(true);
        this.jButton3.setEnabled(true);
      }
      if (e.getSource() == this.jTextField1) {
        this.jTextField2.setEnabled(true);
      }

    }
    if (e.getSource() == jButton2) {
      array = matrixarr.getArray();
      this.setVisible(false);
    }
    if (e.getSource() == this.jButton3) {
      this.setVisible(false);
    }
  }

  public int[][] getArray() {
    return array;
  }

  public TSMatrix getTsmatrix() {

    return matrixarr.getTsmatrix();

  }

  public int getCol() {
    return col;
  }

  public int getRow() {
    return row;
  }

}

⌨️ 快捷键说明

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