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

📄 zhuanpanel.java~9~

📁 cs结构的一个公交车系统好有使用价值啊下吧--- --- ---
💻 JAVA~9~
字号:
package bus;

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

public class ZhuanPanel extends JPanel {
  BorderLayout borderLayout1 = new BorderLayout();
  JTabbedPane jTabbedPane1 = new JTabbedPane();
  JPanel jPanel1 = new JPanel();
  BorderLayout borderLayout2 = new BorderLayout();
  JPanel jPanel2 = new JPanel();
  JPanel jPanel3 = new JPanel();
  JButton bt1 = new JButton();
  JButton bt2 = new JButton();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JLabel jLabel1 = new JLabel();
  JTextField tf1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JTextField tf2 = new JTextField();
  MainFrame mf;
  String s1[] = {
      "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}; //定义钱数大写数组
  String s2[] = {
      "分", "角", "元", "十", "百", "千", "万"}; //定义单位数组
  String str1 = null; //接收输入的小写钱数
  String str3 = null; //存储转换后的大写钱数


  public ZhuanPanel() {
    try {
      jbInit();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  void jbInit() throws Exception {
    this.setLayout(borderLayout1);
    jTabbedPane1.setBackground(new Color(224, 224, 254));
    jTabbedPane1.setFont(new java.awt.Font("Dialog", 0, 16));
    this.setBackground(new Color(224, 224, 254));
    this.setFont(new java.awt.Font("Dialog", 0, 16));
    jPanel1.setBackground(new Color(224, 224, 254));
    jPanel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jPanel1.setLayout(borderLayout2);
    jPanel2.setBackground(new Color(224, 224, 254));
    jPanel2.setLayout(gridBagLayout1);
    jPanel3.setBackground(new Color(224, 224, 254));
    jPanel3.setPreferredSize(new Dimension(10, 60));
    bt1.setBackground(new Color(254, 231, 251));
    bt1.setFont(new java.awt.Font("Dialog", 0, 16));
    bt1.setText("转换");
    bt2.setBackground(new Color(254, 231, 251));
    bt2.setFont(new java.awt.Font("Dialog", 0, 16));
    bt2.setText("取消");
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setText("数字");
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel2.setText("大写");
    tf2.setPreferredSize(new Dimension(160, 25));
    tf2.setText("");
    tf1.setPreferredSize(new Dimension(160, 25));
    tf1.setText("");
    this.add(jTabbedPane1,  BorderLayout.CENTER);
    jTabbedPane1.add(jPanel1,   "大小写转换");
    jPanel1.add(jPanel2,  BorderLayout.CENTER);
    jPanel2.add(tf2,                   new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(13, 0, 11, 0), 0, 0));
    jPanel2.add(tf1, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(11, 40, 7, 40), 0, 0));
    jPanel2.add(jLabel1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 11, 4, 10), 0, 0));
    jPanel2.add(jLabel2, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
            ,GridBagConstraints.SOUTH, GridBagConstraints.NONE, new Insets(7, 1, 9, 0), 0, 0));
    jPanel1.add(jPanel3,  BorderLayout.SOUTH);
    jPanel3.add(bt1, null);
    jPanel3.add(bt2, null);
    bt1.addActionListener(new AL());
    bt2.addActionListener(new AL());
  }

  class AL
      implements ActionListener {
    public void actionPerformed(ActionEvent e) {
      if (e.getSource() == bt1) {
        System.out.println("wwwwwww");
        tf2.setText(str3);
      }
    }
  }
  class Money {
  public Money() {
    try {

      str1 = tf1.getText();
      int flag = check1(str1);
      if (flag == 1) {
        if (str1.indexOf(".") == -1) {
          str3 = zhengShu(str1) + "整";
        }
        else {
          StringTokenizer st = new StringTokenizer(str1, "."); //\u00D2\u00FD\u00C8\u00EB\u00C0à\u00B2\u00F0·\u00D6×\u00D6·\u00FB\u00B4\u00AE
          String str[] = new String[2];
          int i = 0;
          while (st.hasMoreTokens()) {
            str[i] = st.nextToken();
            i++;
          }
          str3 = zhengShu(str[0]);
          str3 = str3 + xiaoShu(str[1]);
        }
        System.out.println(str3);
      }
      else {
        System.out.println("只能输入0-100万之间的数字");
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  public int check1(String chk) {
    int flag = 1;
    for (int i = 0; i < chk.length(); i++) {
      char ch = chk.charAt(i);
      if (ch == '.') {
        continue;
      }
      if (ch == '-' || ch < 48 || ch > 57) {
        flag = 0;
        break;
      }
      else {
        flag = 1;
      }
    }
    if (flag == 1) {
      double money = Double.parseDouble(chk);
      if (money >= 1000000) {
        flag = 0;
      }
    }
    return flag;
  }

  public String zhengShu(String str4) {
    String str2 = "";
    int mon = Integer.parseInt(str4);
    if (mon / 10000 != 0) {
      int wan = mon / 10000;
      if (wan >= 10) {
        String wan1 = wan + "";
        int ff = Integer.parseInt(wan1.charAt(0) + "");
        if (ff != 0) {
          str2 = str2 + s1[ff] + s2[3];
        }
        int gg = Integer.parseInt(wan1.charAt(1) + "");
        if (gg != 0) {
          str2 = str2 + s1[gg];
        }
        str2 = str2 + s2[6];
      }
      else {
        str2 = str2 + s1[wan] + s2[6];
      }
      mon = mon % 10000;
    }
    if (mon / 1000 != 0) {
      int qian = mon / 1000;
      str2 = str2 + s1[qian] + s2[5];
      mon = mon % 1000;
    }
    else {
      if (!str2.equals("") && !str2.endsWith("零")) {
        str2 = str2 + s1[0];
      }
    }
    if (mon / 100 != 0) {
      int bai = mon / 100;
      str2 = str2 + s1[bai] + s2[4];
      mon = mon % 100;
    }
    else {
      if (!str2.equals("") && !str2.endsWith("零")) {
        str2 = str2 + s1[0];
      }
    }
    if (mon / 10 != 0) {
      int shi = mon / 10;
      str2 = str2 + s1[shi] + s2[3];
      mon = mon % 10;
    }
    else {
      if (!str2.equals("") && !str2.endsWith("零")) {
        str2 = str2 + s1[0];
      }
    }
    if (mon / 1 != 0) {
      int ge = mon / 1;
      str2 = str2 + s1[ge] + s2[2];
      mon = mon % 1;
    }
    else {
      str2 = str2.substring(0, str2.lastIndexOf("零")) + "圆";
    }
    return str2;
  }

  public String xiaoShu(String str5) {
    String sss = "";
    int jiao = Integer.parseInt(str5.charAt(0) + "");
    if (jiao != 0) {
      sss = sss + s1[jiao] + s2[1];
    }
    else {
      sss = sss + s1[0] + s2[1];
    }
    try {
      int fen = Integer.parseInt(str5.charAt(1) + "");
      if (fen != 0) {
        sss = sss + s1[fen] + s2[0];
      }
      else {
        sss = sss + s1[0] + s2[0];
      }
    }
    catch (Exception ex) {
      sss = sss + s1[0] + s2[0];
    }
    return sss;
  }
}

}

⌨️ 快捷键说明

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