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

📄 hsdialog.java

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

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

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

//类dataDialog用于建立演示数据
class hsDialog
    extends JDialog
    implements ActionListener {
  private JButton jButton1 = new JButton();
  private JButton jButton2 = new JButton();
  private JButton jButton3 = new JButton();
  private JButton jButton4 = new JButton();
  private JTextField jTextField1 = new JTextField();
  private JLabel jLabel1 = new JLabel();
  //用于保存演示数据
  static int a[] = {
      4, 8, 24, 19, 98, 61, 9, 28, 65, 43, 75, 11, 88, 99, 10};
  public hsDialog(JFrame frame, String title, boolean mode) {
    super(frame, title, mode);
    try {
      jbInit();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    setSize(400, 300);
    setLocation(100, 150);
    setVisible(false);
    jButton1.setBounds(new Rectangle(9, 206, 95, 25));
    jButton1.setToolTipText("随机生成演示数据");
    jButton1.setVerifyInputWhenFocusTarget(true);
    jButton1.setText("随机生成");
    jButton1.addActionListener(this);
    this.getContentPane().setLayout(null);
    jButton2.setBounds(new Rectangle(111, 206, 80, 25));
    jButton2.setToolTipText("演示数据为递增");
    jButton2.setText("升序");
    jButton2.addActionListener(this);
    this.getContentPane().setBackground(SystemColor.activeCaptionBorder);
    jButton3.setBounds(new Rectangle(200, 205, 79, 25));
    jButton3.setToolTipText("演示数据为递减");
    jButton3.setText("降序");
    jButton3.addActionListener(this);
    jButton4.setBounds(new Rectangle(286, 205, 77, 25));
    jButton4.setText("确定");
    jButton4.addActionListener(this);
    jTextField1.setToolTipText("请输入合法数据");
    jTextField1.setText("");
    jTextField1.setBounds(new Rectangle(19, 104, 332, 39));
    jTextField1.addActionListener(this);
    jLabel1.setText("输入0到99之间的整形数据,用逗号分开. (最大个数为17个)");
    jLabel1.setBounds(new Rectangle(19, 24, 355, 37));
    this.getContentPane().add(jLabel1, null);
    this.getContentPane().add(jTextField1, null);
    this.getContentPane().add(jButton1, null);
    this.getContentPane().add(jButton2, null);
    this.getContentPane().add(jButton3, null);
    this.getContentPane().add(jButton4, null);
  }

  public void actionPerformed(ActionEvent e) {
    if (e.getSource() == jButton1) {
      int number = (int) (Math.random() * 2 + 15);
      String s = "";
      for (int i = 0; i < number; i++) {
        int p = (int) (Math.random() * 99 + 1);
        if (i != number - 1)
          s = s + String.valueOf(p) + ",";
        else
          s = s + String.valueOf(p);
      }
      jTextField1.setText(s);
    }
    else if (e.getSource() == jButton2) {
      String s = "";
      int p = 2;
      for (int i = 0; i < 17; i++) {
        p = p + 5;
        if (i != 16)
          s = s + String.valueOf(p) + ",";
        else
          s = s + String.valueOf(p);
      }
      jTextField1.setText(s);
    }
    else if (e.getSource() == jButton3) {

      String s = "";
      int p = 98;
      for (int i = 0; i < 17; i++) {
        p = p - 5;
        if (i != 16)
          s = s + String.valueOf(p) + ",";
        else
          s = s + String.valueOf(p);
      }
      jTextField1.setText(s);
    }
    else if (e.getSource() == jButton4) {
      //用于表示数组a的下标
      int tag = 0;
      String s = jTextField1.getText().trim();
      if (s.equals("")) {
        JOptionPane.showConfirmDialog(this,
                                      "   演示数据不能为空\n \n  请从新输入正确的数据\n",
                                      "出错信息", JOptionPane.DEFAULT_OPTION);
        return;
      }
      StringTokenizer str = new StringTokenizer(s, " ,");
      int number = str.countTokens();
      a = new int[number];
      while (str.hasMoreTokens()) {
        String s1 = str.nextToken();
        try {
          a[tag] = Integer.parseInt(s1);
          if (a[tag] < 0 || a[tag] > 99) {
            JOptionPane.showConfirmDialog(this,
                                          "   输入的数据超出范围\n \n  请从新输入正确的数据\n",
                                          "出错信息", JOptionPane.DEFAULT_OPTION);

            return;

          }

          tag++;
        }
        catch (NumberFormatException e1) {
          JOptionPane.showConfirmDialog(this,
                                        "   输入的数据不合法\n \n  请从新输入正确的数据\n",
                                        "出错信息", JOptionPane.DEFAULT_OPTION);

          return;
        }
      }
      if (tag >= 18) {
        JOptionPane.showConfirmDialog(this,
                                      "   输入的数据个数大于17个\n \n  请从新输入正确的数据\n",
                                      "出错信息", JOptionPane.DEFAULT_OPTION);

        return;

      }
      setVisible(false);
    }
  }
}

⌨️ 快捷键说明

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