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

📄 upusebalance.java

📁 一个简单的机房管理系统 可以简单的实现查询,计费 上下机,充值等功能
💻 JAVA
字号:
package src.netbar;

import java.awt.*;
import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import src.Bean.UpComputerCardBean;
import src.Rule.adminCardRule;
import java.sql.*;
import src.Rule.DownComputerRule;
import src.Rule.Sound;

/**
 * 帐号充值
 */
public class upUseBalance
    extends JFrame {
  UpComputerCardBean CardUseBean = new UpComputerCardBean();
  adminCardRule adminRule;
  DownComputerRule downRule;
  public upUseBalance() {
    try {
      jbInit();
    }
    catch (Exception exception) {
      exception.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    adminRule = new adminCardRule();
    downRule = new DownComputerRule();
    getContentPane().setLayout(null);
    this.setBounds(440, 250, 570, 390);
    setSize(new Dimension(400, 300));
    this.setTitle("机房管理系统 -- 充值用户帐号");
    this.setResizable(false);
    jLabel1.setFont(new java.awt.Font("黑体", Font.PLAIN, 24));
    jLabel1.setForeground(Color.blue);
    jLabel1.setText("用户帐号充值");
    jLabel1.setBounds(new Rectangle(119, 43, 151, 41));
    jLabel2.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jLabel2.setText("用户帐号");
    jLabel2.setBounds(new Rectangle(77, 102, 66, 31));
    jLabel3.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    jLabel3.setText("充值金额");
    jLabel3.setBounds(new Rectangle(77, 145, 66, 35));
    txtUseName.setBounds(new Rectangle(163, 105, 138, 26));
    txtuserBalance.setBounds(new Rectangle(161, 148, 141, 27));
    butOK.setBounds(new Rectangle(103, 200, 84, 30));
    butOK.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    butOK.setText("确定");
    butOK.addActionListener(new upUseBalance_butOK_actionAdapter(this));
    butClare.setBounds(new Rectangle(211, 200, 86, 31));
    butClare.setFont(new java.awt.Font("Dialog", Font.PLAIN, 14));
    butClare.setText("重填");
    butClare.addActionListener(new upUseBalance_butClare_actionAdapter(this));
    this.getContentPane().add(txtUseName);
    this.getContentPane().add(txtuserBalance);
    this.getContentPane().add(jLabel2);
    this.getContentPane().add(jLabel3);
    this.getContentPane().add(butOK);
    this.getContentPane().add(butClare);
    this.getContentPane().add(jLabel1);

  }

  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JTextField txtUseName = new JTextField();
  JTextField txtuserBalance = new JTextField();
  JButton butOK = new JButton();
  JButton butClare = new JButton();
  public void butClare_actionPerformed(ActionEvent e) {
    this.txtUseName.setText("");
    this.txtuserBalance.setText("");
  }

  public void butOK_actionPerformed(ActionEvent e) {
    String name = this.txtUseName.getText();
    String money = this.txtuserBalance.getText();
    CardUseBean.setUserName(name);
    try {
      float Money = Float.parseFloat(money);
      CardUseBean.setBalace(Money);
    }
    catch (Exception FloatEX) {
    }

    if (name.length() == 0) {
      JOptionPane.showMessageDialog(this, "用户名不能为空!!", "提示",
                                    JOptionPane.PLAIN_MESSAGE,
                                    new ImageIcon("imags\\baichi.gif"));
    }
    else {
      try {
        if (adminRule.chickUserName(CardUseBean)) {
          if (money.length() == 0) {
            JOptionPane.showMessageDialog(this, "充值金额未填写!!", "提示",
                                          JOptionPane.PLAIN_MESSAGE,
                                          new ImageIcon("imags\\baichi.gif"));
          }
          else {
            try {
              float Money = Float.parseFloat(money);
              CardUseBean.setBalace(Money);
              if ( (Money < 10) || (Money > 1000)) {
                JOptionPane.showMessageDialog(this,
                                              "充值金额不能低于10元。\n且不能高于1000元!!",
                                              "提示",
                                              JOptionPane.PLAIN_MESSAGE,
                                              new ImageIcon(
                                                  "imags\\baichi.gif"));
                this.txtuserBalance.setText("");
              }
              else {
                // JOptionPane.showMessageDialog(this, "OK");
                adminRule.insertBalance(CardUseBean);
                float tolMoney = downRule.getCardBalance(CardUseBean);
                JOptionPane.showMessageDialog(this,
                                              "充值成功!!\n你已成功充值:" + money +
                                              "元!\n你的可用余额为:" + tolMoney+"元!",
                                              "欢迎您的使用!!",
                                              JOptionPane.PLAIN_MESSAGE,
                                              new ImageIcon(
                                                  "imags\\money.gif"));
                this.txtUseName.setText("");
                this.txtuserBalance.setText("");
              }
            }
            catch (Exception FloatEX) {
            }
          }
        }
        else {
          JOptionPane.showMessageDialog(this, "用户名不存在!!", "提示",
                                        JOptionPane.PLAIN_MESSAGE,
                                        new ImageIcon("imags\\baichi.gif"));
          this.txtUseName.setText("");
        }
      }
      catch (SQLException ex) {
      }
    }
  }

  class upUseBalance_butOK_actionAdapter
      implements ActionListener {
    private upUseBalance adaptee;
    upUseBalance_butOK_actionAdapter(upUseBalance adaptee) {
      this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
      adaptee.butOK_actionPerformed(e);
    }
  }

  class upUseBalance_butClare_actionAdapter
      implements ActionListener {
    private upUseBalance adaptee;
    upUseBalance_butClare_actionAdapter(upUseBalance adaptee) {
      this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
      adaptee.butClare_actionPerformed(e);
    }
  }
}

⌨️ 快捷键说明

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