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

📄 paydialog.java

📁 好的超市源码供大家下载
💻 JAVA
字号:
package view.dialog.posdialog;

import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import view.com.CenterDialog;
import view.com.GBC;
import view.com.SetFont;
import view.com.consts.FontConst;
import view.frame.PosFrame;
import action.implementclass.menuaction.PosMenuActionImp;

import common.jdbc.DbException;

import dao.SaleDao;
import dao.StoreDao;

/**
 * 付款对话框
 * @author linfeng
 *
 */
public class PayDialog extends JDialog {

  /**
   * payDialog 付款对话框
   * pay 应付标签
   * give 已给标签
   * give_back 应找标签
   * payText 应付文本框
   * giveText 已给文本框
   * give_backText 应找文本框
   * okButton 确定按钮
   * calButton 结算按钮
   * payValue 应付值
   * giveValue 已给值
   */
  private JDialog payDialog;
  private JLabel pay, give, give_back;
  public static JTextField payText, giveText, give_backText;
  private JButton okButton, calButton;
  private double payValue, giveValue;
  
  public PayDialog() {
    payDialog = new JDialog();
    payDialog.setTitle("付款");
    payDialog.setLayout(new GridBagLayout());
    initial();
    payDialog.add(pay, new GBC(0, 0).setAnchor(GBC.EAST).setInset(0, 0, 5, 7));
    payDialog.add(payText, new GBC(1, 0).setAnchor(GBC.WEST).setInset(0, 0, 5,
        0));
    payDialog.add(give, new GBC(0, 1).setAnchor(GBC.EAST).setInset(0, 0, 5, 7));
    payDialog.add(giveText, new GBC(1, 1).setAnchor(GBC.WEST).setInset(0, 0, 5,
        0));
    payDialog.add(give_back, new GBC(0, 2).setAnchor(GBC.EAST).setInset(0, 0,
        5, 7));
    payDialog.add(give_backText, new GBC(1, 2).setAnchor(GBC.WEST).setInset(0,
        0, 5, 0));
    payDialog.add(okButton, new GBC(0, 3).setAnchor(GBC.EAST).setInset(10, 0,
        5, 25));
    payDialog.add(calButton, new GBC(1, 3).setAnchor(GBC.EAST).setInset(10, 0,
        5, 0));
    payDialog.setSize(300, 200);
    new CenterDialog().getCenterDialog(payDialog, true);
    payDialog.setVisible(true);
  }

  /**
   * 初始化各种文本框
   */
  public void initialText() {
    payText.setText("0");
    giveText.setText("0");
    
    give_backText.setEditable(false);
  }

  /**
   * 初始化各种组件,并添加相应的事件
   */
  public void initial() {
    pay = new JLabel("应付金额: ");
    pay.setFont(SetFont.getFont(FontConst.KAITI_BOLD_15));
    give = new JLabel("付款金额: ");
    give.setFont(SetFont.getFont(FontConst.KAITI_BOLD_15));
    give_back = new JLabel("找还金额: ");
    give_back.setFont(SetFont.getFont(FontConst.KAITI_BOLD_15));
    payText = new JTextField(10);
    giveText = new JTextField(10);
    give_backText = new JTextField(10);
    give_backText.setEditable(false);
    initialText();
    okButton = new JButton("确定");
    okButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SaleDao dao = new SaleDao();
        StoreDao sdao = new StoreDao();
        try{
          if (dao.insertSale(PosMenuActionImp.value)) {
            JOptionPane.showMessageDialog(null, "该商品已经成功售出", "提示",
                JOptionPane.YES_OPTION);
                           
            sdao.updateStoreById(Integer.parseInt(PosFrame.product_idText
                .getText()), Integer.parseInt(PosFrame.product_numText.getText()));
          }
        }catch(DbException ex){
          JOptionPane.showMessageDialog(null, ex.getMessage(), "错误",
              JOptionPane.ERROR_MESSAGE);
        }
        payDialog.dispose();
      }
    });
    calButton = new JButton("结算");
    calButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        payValue = Double.parseDouble(payText.getText().trim());
        giveValue = Double.parseDouble(giveText.getText().trim());
        
        give_backText.setText(new Double(Double
            .parseDouble((giveText.getText()))
            - Double.parseDouble((payText.getText()))).toString());
      }
    });
  }
  
}

⌨️ 快捷键说明

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