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

📄 addpayoutdialog.java

📁 这是一个完全的开发实例
💻 JAVA
字号:

package personal_payout_manage.frame;

import javax.swing.*;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Dimension;
import java.util.Date;
import personal_payout_manage.ejbs.PayoutSession;
import personal_payout_manage.utils.SessionBeanFactory;
import java.util.*;
import java.rmi.*;
import personal_payout_manage.wrappedobject.PersonObject;
import personal_payout_manage.wrappedobject.MaterialObject;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import personal_payout_manage.wrappedobject.PayoutObject;
import java.sql.Timestamp;

public class AddPayoutDialog
    extends JDialog {
  private PersonalPayoutManageFrame frame = new PersonalPayoutManageFrame();
  public AddPayoutDialog(PersonalPayoutManageFrame frame ,String title ,boolean model) {
    super(frame,title,model);
    this.frame = frame;
    try {
      jbInit();
      if (frame.action.equalsIgnoreCase("edit"))
        initPayoutDate();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  private void jbInit() throws Exception {
    this.getContentPane().setLayout(xYLayout1);
    this.setSize(new Dimension(340,400));
    setJComboxItems();
    jLabel1.setText("支出明细编号");
    jLabel5.setText("费用");
    jLabel4.setText("支出时间");
    jLabel3.setText("物品");
    jLabel2.setText("人员");
    jButton1.setText("确 定");
    jButton1.addActionListener(new AddPayoutDialog_jButton1_actionAdapter(this));
    jButton2.setText("取 消");
    jButton2.addActionListener(new AddPayoutDialog_jButton2_actionAdapter(this));
    jFormattedTextField1.setValue(new Date());
    jLabel6.setText("备注");
    this.getContentPane().add(jLabel5, new XYConstraints(57, 187, -1, -1));
    this.getContentPane().add(jLabel4, new XYConstraints(35, 144, -1, -1));
    this.getContentPane().add(jLabel3, new XYConstraints(57, 101, -1, -1));
    this.getContentPane().add(jLabel1, new XYConstraints(13, 14, -1, -1));
    this.getContentPane().add(jComboBox2, new XYConstraints(100, 101, -1, -1));
    this.getContentPane().add(jComboBox1, new XYConstraints(100, 58, -1, -1));
    this.getContentPane().add(jTextField2, new XYConstraints(100, 190, 103, -1));
    this.getContentPane().add(jTextField1, new XYConstraints(100, 14, 103, -1));
    this.getContentPane().add(jLabel2, new XYConstraints(57, 60, -1, -1));
    this.getContentPane().add(jScrollPane1, new XYConstraints(100, 228, 103, 56));
    this.getContentPane().add(jFormattedTextField1,
                              new XYConstraints(100, 144, 103, -1));
    this.getContentPane().add(jLabel6, new XYConstraints(35, 233, -1, -1));
    this.getContentPane().add(jButton2, new XYConstraints(202, 307, -1, -1));

    this.getContentPane().add(jButton1, new XYConstraints(100, 307, -1, -1));
    jScrollPane1.getViewport().add(jTextArea1);
  }
  //初始化支出明细的记录
  private void initPayoutDate()
  {
    int row = frame.payoutTable.getSelectedRow();
    Long  id  = (Long)frame.payoutData[row][0];
    PayoutSession sb = SessionBeanFactory.getPayoutSessionBean("PayoutSessionBean");
    try {
      PayoutObject po = sb.getPayoutListById(id);
      jTextField1.setText(String.valueOf(po.getId()));
      jTextField1.setEditable(false);
      jComboBox1.setSelectedItem(po.getPsn());
      jComboBox2.setSelectedItem(po.getMsn());
      jFormattedTextField1.setText(String.valueOf(po.getPayoutTime()).substring(0,10));
      jTextField2.setText(String.valueOf(po.getSpendMoney()));
      jTextArea1.setText(po.getNote());
    }
    catch (RemoteException ex) {
    }
  }
  //初始化人员列表和物品列表
  private void setJComboxItems()
  {
    PayoutSession sb = SessionBeanFactory.getPayoutSessionBean("PayoutSessionBean");
    Collection col1 = null;
    Collection col2 = null;
    try {
      col1 = sb.getAllPerson();
      col2 = sb.getAllMaterial();
    }
    catch (RemoteException ex) {
    }
    for (Iterator iter = col1.iterator(); iter.hasNext(); ) {
      PersonObject item = (PersonObject) iter.next();
      jComboBox1.addItem(item);
    }
    for (Iterator iter = col2.iterator(); iter.hasNext(); ) {
      MaterialObject item = (MaterialObject) iter.next();
      jComboBox2.addItem(item);
    }
  }
  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel1 = new JLabel();
  JTextField jTextField1 = new JTextField();
  JLabel jLabel2 = new JLabel();
  JComboBox jComboBox1 = new JComboBox();
  JLabel jLabel3 = new JLabel();
  JComboBox jComboBox2 = new JComboBox();
  JLabel jLabel4 = new JLabel();
  JFormattedTextField jFormattedTextField1 = new JFormattedTextField();
  JLabel jLabel5 = new JLabel();
  JTextField jTextField2 = new JTextField();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JLabel jLabel6 = new JLabel();
  JScrollPane jScrollPane1 = new JScrollPane();
  JTextArea jTextArea1 = new JTextArea();
  public void jButton2_actionPerformed(ActionEvent e) {
        this.dispose();
  }

  public void jButton1_actionPerformed(ActionEvent e) {
    try {
          if (passVerify()) {
            PayoutObject updateob = new PayoutObject(Long.valueOf(jTextField1.
                getText()), jComboBox1.getSelectedItem().toString(),
                jComboBox2.getSelectedItem().toString(), Timestamp.valueOf(jFormattedTextField1.getText()+" 12:12:59.000000000"),
                Float.valueOf(jTextField2.getText()),
                jTextArea1.getText());
           PayoutSession sb = SessionBeanFactory.getPayoutSessionBean("PayoutSessionBean");
           //更新角色资料
           if (frame.action.equals("edit"))
             sb.updatePayoutById(updateob.getId(),updateob);
           //保存新的角色
           else
             sb.saveNewPayout(updateob);

           frame.refreshPayoutView();
           this.dispose();
         }
       }
       catch (NumberFormatException ex) {
         ex.printStackTrace();
       }
       catch (RemoteException ex) {
         ex.printStackTrace();
       }
  }
  private boolean passVerify() {
    try {
      if (jTextField1.getText() == null ||
          jTextField1.getText().trim().equals(""))
        throw new Exception("注意:支出编号不能为空而起不能与数据库卡中已有的编号相重复!");
      if (jTextField2.getText() == null ||
          jTextField2.getText().trim().equals(""))
        throw new Exception("注意:费用不能为空!");
      Float.parseFloat(jTextField2.getText());
      return true;
    }
    catch (Exception ne) {
      JOptionPane.showMessageDialog(null, ne.getMessage(), "配置用户",
                                    JOptionPane.ERROR_MESSAGE);
    }
    return false;
  }
  }
class AddPayoutDialog_jButton1_actionAdapter
    implements ActionListener {
  private AddPayoutDialog adaptee;
  AddPayoutDialog_jButton1_actionAdapter(AddPayoutDialog adaptee) {
    this.adaptee = adaptee;
  }

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

class AddPayoutDialog_jButton2_actionAdapter
    implements ActionListener {
  private AddPayoutDialog adaptee;
  AddPayoutDialog_jButton2_actionAdapter(AddPayoutDialog adaptee) {
    this.adaptee = adaptee;
  }

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

⌨️ 快捷键说明

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