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

📄 tushumanagelistener1.java

📁 java+sql 图书管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package MyLibraryok.books.untitled1;

import java.awt.*;
import java.awt.event.*;
import java.sql.*;

import javax.swing.*;
import java.awt.Toolkit;
import java.awt.Dimension;

import java.util.ArrayList;
import MyLibraryok.Mydb.Mydb;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class TushuManageListener1 implements ActionListener, MouseListener {
    static int as;
    static String ks;
    static String r;
    Feifa fei = new Feifa();

    Mydb mydb;
    JTable jtable;
    TushuManage tu1;
    static String jj;
    public TushuManageListener1(TushuManage tu1) {
        this.tu1 = tu1;
    }

    public TushuManageListener1(Mydb mydb) {
        this.mydb = mydb;
    }

    public TushuManageListener1(JTable jtable) {
        this.jtable = jtable;
    }


    public void actionPerformed(ActionEvent e) {

        if (e.getSource() == tu1.jButton1) {
            String baiqong = "select *from books";
            tu1.bookdo(baiqong);

        } else if (e.getSource() == tu1.jButton11) {

            new ChaXunJM(tu1);
        } else if (e.getActionCommand().equals("取消")) { //当按"取消"键时,实现监听
            tu1.jButton5.setEnabled(true);    //设置按纽变灰
            tu1.jButton6.setEnabled(true);
            tu1.jButton7.setEnabled(true);
            tu1.jButton8.setEnabled(true);
            tu1.jButton9.setEnabled(true);
            tu1.jButton10.setEnabled(true);

        }

        /************************************************删除按纽的监听***************************************************/

        else if (e.getActionCommand().equals("删除")) { //当按"删 除"键时,实现监听
            int row1 = tu1.jTable1.getSelectedRow();
            if (row1 == -1) {
                JOptionPane.showMessageDialog(null, "请选择要删除的记录!!!", "温馨提示",
                                              JOptionPane.
                                              INFORMATION_MESSAGE);
            } else {
                int aaa = JOptionPane.showConfirmDialog(null, "确定要删除本条记录吗?",
                        "温馨提示!",
                        JOptionPane.YES_NO_OPTION);
                if (aaa == JOptionPane.YES_OPTION) {

                    String rrew = String.valueOf(tu1.modle.getValueAt(row1,
                            0));
                    try {
                        Mydb ddd = new Mydb();
                        String asd = "delete books where 图书编号=" + rrew;
                        ddd.sqlzen(asd);
                        tu1.list.remove(row1);
                        tu1.modle.fireTableDataChanged();
                    } catch (SQLException t) {
                        t.printStackTrace();
                    }

                    JOptionPane.showMessageDialog(null,
                                                  "本条记录已经删除!",
                                                  "温馨提示!",
                                                  JOptionPane.
                                                  INFORMATION_MESSAGE); //弹出相应对话框

                } else {}
            }
        }

        /*************************************************返回按钮的监听********************************************************/
        else if (e.getActionCommand().equals("返回")) {
            int s = JOptionPane.showConfirmDialog(null, "是否退出", "退出",
                                                  JOptionPane.YES_NO_OPTION);
            if (s == JOptionPane.YES_OPTION) {
                tu1.dispose();

            } else {

            }

        }

        /**************************************************编辑按钮的监听********************************************************/
        else if (e.getActionCommand().equals("编辑")) { //当按"编辑"键时,实现监听
            tu1.jTextShuMing.requestFocus();           //设置文本框为不可编辑
            tu1.jTextZuoZhe.setEnabled(true);
            tu1.jTextTiaoXingMa.setEnabled(true);
            tu1.jTextShuMing.setEnabled(true);
            tu1.jTextDingJia.setEnabled(true);
            tu1.jTextLeiBie.setEnabled(true);
            tu1.jTextChuBanShe.setEnabled(true);
            tu1.jTextCunFang.setEnabled(true);
            tu1.jTextField1.setEnabled(true);
            tu1.jTextKuCunTushu.setEnabled(true);
            tu1.jTextRuKuShijian.setEnabled(true);
            tu1.jTextJieChunTushu.setEnabled(true);
            int as = tu1.jTable1.getSelectedRow();

            if (as == -1) { //如果没有选取要编辑的行,那么弹出相应对话框
                JOptionPane.showMessageDialog(null, "请选择要编辑的图书", "温馨提示",
                                              JOptionPane.
                                              INFORMATION_MESSAGE);
            } else {
                int ii = JOptionPane.showConfirmDialog(null, "确定要修改吗?",
                        "温馨提示",
                        JOptionPane.YES_NO_OPTION);
                if (ii == JOptionPane.YES_OPTION) {
                    tu1.jTextShuMing.requestFocus();
                    tu1.jButton5.setEnabled(false);
                    tu1.jButton6.setEnabled(false);
                    tu1.jButton7.setEnabled(false);
                    tu1.jButton8.setEnabled(false);
                    tu1.jButton9.setEnabled(false);
                    tu1.jButton10.setEnabled(true);
                    String strBH = tu1.jTextBiaoHao.getText();
                    String strTXM = tu1.jTextTiaoXingMa.getText();
                    String strSN = tu1.jTextShuMing.getText();
                    String strDJ = tu1.jTextDingJia.getText();
                    String strCF = tu1.jTextCunFang.getText();
                    String strLB = tu1.jTextLeiBie.getText();
                    String strCBS = tu1.jTextChuBanShe.getText();
                    String strZZ = tu1.jTextZuoZhe.getText();
                    String strZT = tu1.jTextField1.getText();
/////////////////////////////////在全局定new个非法类,在这里调用非法类/////////////////////////////////////
                    if (fei.feifatiaoxingma(strTXM)) {
                        tu1.jTextTiaoXingMa.setText("");
                        tu1.jTextTiaoXingMa.requestFocus();
                    } else if (fei.feifamingcheng(strSN)) {
                        tu1.jTextShuMing.setText("");
                        tu1.jTextShuMing.requestFocus();
                    } else if (fei.feifazuozhe(strZZ)) {
                        tu1.jTextZuoZhe.setText("");
                        tu1.jTextZuoZhe.requestFocus();
                    } else if (fei.feifajiage(strDJ)) {
                        tu1.jTextDingJia.setText("");
                        tu1.jTextDingJia.requestFocus();

                    } else if (fei.feifaleibie(strLB)) {
                        tu1.jTextLeiBie.setText("");
                        tu1.jTextLeiBie.requestFocus();
                    } else if (fei.feifachubanshe(strCBS)) {
                        tu1.jTextChuBanShe.setText("");
                        tu1.jTextChuBanShe.requestFocus();

                    } else {
                        try {
                            Mydb my = new Mydb();
                            my.sqlgai("update books set 图书名称 = '" +
                                      tu1.jTextShuMing.getText() + "',条形码='" +
                                      tu1.jTextTiaoXingMa.getText() + "',类别 ='" +
                                      tu1.jTextLeiBie.getText() + "',出版社 ='" +
                                      tu1.jTextChuBanShe.getText() +
                                      "',存放位置 ='" +
                                      tu1.jTextCunFang.getText() + "',定价 ='" +
                                      tu1.jTextDingJia.getText() + "',状态 ='" +
                                      tu1.jTextField1.getText() + "',作者 ='" +
                                      tu1.jTextZuoZhe.getText() +"',库存图书 ='"+
                                      tu1.jTextKuCunTushu.getText()+
                                      "'where 图书编号 = " +
                                      ks);
                        } catch (SQLException ex) {
                            ex.printStackTrace();
                        }
                        JOptionPane.showMessageDialog(null, "编辑成功,表的内容已修改!!!",
                                "图书管理系统",
                                JOptionPane.OK_OPTION);

                    }
                }

                String str = "select *from books";
                tu1.bookdo(str); //调用bookdo方法
                tu1.jButton5.setEnabled(true);
                tu1.jButton6.setEnabled(true);

⌨️ 快捷键说明

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