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

📄 dlglibadd.java~24~

📁 用java实现的一个应用程序,源码非常完整,可以直接运行
💻 JAVA~24~
字号:
package 毕业设计;

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

public class dlgLibAdd extends JDialog {
    JLabel lblId = new JLabel();
    JTextField txtId = new JTextField();
    JLabel lblBarCode = new JLabel();
    JTextField txtBarCode = new JTextField();
    JLabel lblName = new JLabel();
    JTextField txtName = new JTextField();
    JLabel lblAuthor = new JLabel();
    JTextField txtAuthor = new JTextField();
    JLabel lblSynopsis = new JLabel();
    JTextArea txtSynopsis = new JTextArea();
    JLabel lblPublish = new JLabel();
    JLabel lblPrice = new JLabel();
    JLabel lblSort = new JLabel();
    JLabel lblIntoTime = new JLabel();
    JLabel lblLocation = new JLabel();
    JTextField txtPrice = new JTextField();
    JTextField txtIntoTime = new JTextField();
    JLabel lblIsbn = new JLabel();
    JTextField txtIsbn = new JTextField();
    JComboBox cbbPublish = new JComboBox();
    JComboBox cbbSort = new JComboBox();
    JTextField txtLocation = new JTextField();
    JButton btnAdd = new JButton();
    JButton btnCancel = new JButton();
    JButton btnExit = new JButton();
    JLabel lblLine = new JLabel();
    JLabel lblPage = new JLabel();
    JTextField txtPage = new JTextField();
    public dlgLibAdd() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        setSize(new Dimension(700, 530));
        setTitle("图书添加");
        lblId.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblId.setText("编      号:");
        lblId.setBounds(new Rectangle(30, 19, 74, 28));
        txtId.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtId.setBounds(new Rectangle(110, 19, 208, 28));
        lblBarCode.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblBarCode.setText("条 形 码:");
        lblBarCode.setBounds(new Rectangle(30, 71, 75, 28));
        txtBarCode.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtBarCode.setText("");
        txtBarCode.setBounds(new Rectangle(110, 71, 208, 28));
        lblName.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtName.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtName.setText("");
        txtName.setBounds(new Rectangle(110, 125, 208, 28));
        lblAuthor.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblAuthor.setText("作     者:");
        lblAuthor.setBounds(new Rectangle(30, 182, 87, 28));
        txtAuthor.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtAuthor.setText("");
        txtAuthor.setBounds(new Rectangle(110, 181, 208, 28));
        lblSynopsis.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblSynopsis.setText("简       介:");
        lblSynopsis.setBounds(new Rectangle(352, 177, 76, 38));
        txtSynopsis.setText("");
        txtSynopsis.setBounds(new Rectangle(354, 209, 307, 217));
        lblName.setText("名     称:");
        lblName.setBounds(new Rectangle(30, 123, 77, 28));
        lblPublish.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblPublish.setText("出 版 社:");
        lblPublish.setBounds(new Rectangle(30, 240, 69, 28));
        lblPrice.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblPrice.setText("价     格:");
        lblPrice.setBounds(new Rectangle(30, 353, 74, 28));
        lblSort.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblSort.setText("类       别:");
        lblSort.setBounds(new Rectangle(350, 18, 79, 28));
        lblIntoTime.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblIntoTime.setText("入库时间:");
        lblIntoTime.setBounds(new Rectangle(350, 73, 86, 28));
        lblLocation.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblLocation.setText("存放位置:");
        lblLocation.setBounds(new Rectangle(350, 131, 82, 28));
        txtPrice.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtPrice.setText("");
        txtPrice.setBounds(new Rectangle(110, 295, 208, 28));
        txtIntoTime.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtIntoTime.setText(getNowTime());
        txtIntoTime.setBounds(new Rectangle(433, 71, 225, 28));
        lblIsbn.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblIsbn.setText("I S B N:");
        lblIsbn.setBounds(new Rectangle(33, 296, 65, 28));
        txtIsbn.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtIsbn.setText("");
        txtIsbn.setBounds(new Rectangle(110, 351, 208, 28));
        cbbPublish.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        cbbPublish.setBounds(new Rectangle(110, 238, 208, 29));
        cbbSort.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        cbbSort.setBounds(new Rectangle(434, 19, 225, 28));
        txtLocation.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtLocation.setText("");
        txtLocation.setBounds(new Rectangle(434, 126, 225, 28));
        btnAdd.setBounds(new Rectangle(123, 463, 96, 28));
        btnAdd.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        btnAdd.setText("添加");
        btnAdd.addActionListener(new dlgLibAdd_btnAdd_actionAdapter(this));
        btnCancel.setBounds(new Rectangle(308, 461, 97, 28));
        btnCancel.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        btnCancel.setText("清空");
        btnCancel.addActionListener(new dlgLibAdd_btnCancel_actionAdapter(this));
        btnExit.setBounds(new Rectangle(480, 461, 87, 28));
        btnExit.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        btnExit.setText("退出");
        btnExit.addActionListener(new dlgLibAdd_btnExit_actionAdapter(this));
        lblLine.setBorder(BorderFactory.createEtchedBorder());
        lblLine.setText("");
        lblLine.setBounds(new Rectangle(24, 9, 646, 437));
        lblPage.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        lblPage.setText("总 页 数:");
        lblPage.setBounds(new Rectangle(26, 396, 78, 32));
        txtPage.setFont(new java.awt.Font("Dialog", Font.PLAIN, 18));
        txtPage.setText("");
        txtPage.setBounds(new Rectangle(107, 399, 210, 29));
        this.getContentPane().add(txtSynopsis);
        this.getContentPane().add(txtLocation);
        this.getContentPane().add(lblLocation);
        this.getContentPane().add(txtIntoTime);
        this.getContentPane().add(lblIntoTime);
        this.getContentPane().add(cbbSort);
        this.getContentPane().add(txtId);
        this.getContentPane().add(lblId);
        this.getContentPane().add(txtName);
        this.getContentPane().add(txtBarCode);
        this.getContentPane().add(lblSort);
        this.getContentPane().add(txtAuthor);
        this.getContentPane().add(cbbPublish);
        this.getContentPane().add(lblPublish);
        this.getContentPane().add(lblName);
        this.getContentPane().add(lblBarCode);
        this.getContentPane().add(lblSynopsis);
        this.getContentPane().add(lblAuthor);
        this.getContentPane().add(txtPrice);
        this.getContentPane().add(txtIsbn);
        this.getContentPane().add(lblPrice);
        this.getContentPane().add(lblIsbn);
        this.getContentPane().add(btnAdd);
        this.getContentPane().add(btnExit);
        this.getContentPane().add(lblPage);
        this.getContentPane().add(txtPage);
        this.getContentPane().add(lblLine);
        this.getContentPane().add(btnCancel);
        this.setResizable(false);
        DisplayPublish();
        DisplaySort();
    }

    public String getNowTime() {
        Calendar c = Calendar.getInstance();
        java.sql.Date dd = new java.sql.Date(c.getTimeInMillis());
        java.sql.Time tt = new java.sql.Time(c.getTimeInMillis());
        String NowTime;
        NowTime = dd.toString();
        return NowTime;
    }

    public void DisplayPublish() {
        Vector vt;
        PublishConDB publishDB = new PublishConDB();
        vt = publishDB.SearchAll();
        for (int i = 0; i < vt.size(); i++) {
            cbbPublish.addItem(((Vector) (vt.get(i))).get(1));
        }
    }

    public void DisplaySort() {
        Vector vt;
        SortConDB sortDB = new SortConDB();
        vt = sortDB.SearchAll();
        for (int i = 0; i < vt.size(); i++) {
            cbbSort.addItem(((Vector) (vt.get(i))).get(1));
        }
    }

    public void ShowLibAdd() {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension dlgSize = this.getSize();
        if (dlgSize.height > screenSize.height) {
            dlgSize.height = screenSize.height;
        }
        if (dlgSize.width > screenSize.width) {
            dlgSize.width = screenSize.width;
        }
        this.setLocation((screenSize.width - dlgSize.width) / 2,
                         (screenSize.height - dlgSize.height) / 2);
        this.setModal(true);
        this.setVisible(true);
    }

    public void btnAdd_actionPerformed(ActionEvent e) {
        String Id = txtId.getText();
        String BarCode = txtBarCode.getText();
        String Name = txtName.getText();
        String Author = txtAuthor.getText();
        String Page = txtPage.getText();
        String Publish = cbbPublish.getSelectedItem().toString();
        String Isbn = txtIsbn.getText();
        String Price = txtPrice.getText();
        String Sort = cbbSort.getSelectedItem().toString();
        String IntoTime = txtIntoTime.getText();
        String Location = txtLocation.getText();
        String Synopsis = txtSynopsis.getText();
        if (Id.equals("")) {
            JOptionPane.showMessageDialog(this, "图书编号不能为空!");
        } else if (BarCode.equals("")) {
            JOptionPane.showMessageDialog(this, "图书条形码不能为空!");
        } else {
            if (Name.equals("")) {
                Name = "不详";
            }
            if (Author.equals("")) {
                Author = "不详";
            }
            if (Page.equals("")) {
                Page = "不详";
            }
            if (Isbn.equals("")) {
                Isbn = "不详";
            }
            if (Price.equals("")) {
                Price = "不详";
            }
            if (IntoTime.equals("")) {
                IntoTime = "不详";
            }

            if (Location.equals("")) {
                Location = "不详";
            }
            if (Synopsis.equals("")) {
                Synopsis = "没有简介";
            }
            BookConDB bookDB = new BookConDB();
            bookDB.AddBook(Id, BarCode, Name, Author, Page, Publish, Isbn,
                           Price, Sort, IntoTime, Location, Synopsis);
            if (bookDB.SearchBook(Id, "", "", "", "", "", true).size() < 1) {
                bookDB.CloseBookDB();
                JOptionPane.showMessageDialog(this, "添加失败,请不要输入特殊符号!");
                return;
            }
            bookDB.CloseBookDB();
            JOptionPane.showMessageDialog(this, "添加成功!");
        }
    }

    public void btnCancel_actionPerformed(ActionEvent e) {
        txtId.setText("");
        txtBarCode.setText("");
        txtName.setText("");
        txtAuthor.setText("");
        txtPage.setText("");
        cbbPublish.setSelectedIndex(0);
        txtIsbn.setText("");
        txtPrice.setText("");
        cbbSort.setSelectedIndex(0);
        txtLocation.setText("");
        txtSynopsis.setText("");
    }

    public void btnExit_actionPerformed(ActionEvent e) {
        this.dispose();
    }
}

class dlgLibAdd_btnExit_actionAdapter implements ActionListener {
    private dlgLibAdd adaptee;
    dlgLibAdd_btnExit_actionAdapter(dlgLibAdd adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgLibAdd_btnCancel_actionAdapter implements ActionListener {
    private dlgLibAdd adaptee;
    dlgLibAdd_btnCancel_actionAdapter(dlgLibAdd adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgLibAdd_btnAdd_actionAdapter implements ActionListener {
    private dlgLibAdd adaptee;
    dlgLibAdd_btnAdd_actionAdapter(dlgLibAdd adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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