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

📄 dlgvocation.java

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

import java.awt.*;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentAdapter;
import javax.swing.table.*;
import java.util.Vector;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;

public class dlgVocation extends JDialog {

    JTable tblDisplay = new JTable();
    JTextField txtVocation = new JTextField();
    JButton btnSearch = new JButton();
    JButton btnUpdate = new JButton();
    JButton btnDelete = new JButton();
    JButton btnExit = new JButton();
    JButton btnAdd = new JButton();
    DefaultTableModel dt;
    Vector vtColName = new Vector();
    Vector vt;
    JScrollPane jScrollPane1 = new JScrollPane();
    public dlgVocation() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        setSize(new Dimension(326, 471));
        this.setTitle("读者职业维护");
        tblDisplay.setBounds(new Rectangle(20, 25, 274, 281));
        tblDisplay.addMouseListener(new dlgVocation_tblDisplay_mouseAdapter(this));
        btnSearch.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnUpdate.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnAdd.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnDelete.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnExit.setFont(new java.awt.Font("Dialog", Font.PLAIN, 15));
        btnAdd.setBounds(new Rectangle(133, 368, 75, 27));
        btnAdd.setText("添加");
        btnAdd.addActionListener(new dlgVocation_btnAdd_actionAdapter(this));
        btnExit.setBounds(new Rectangle(224, 404, 75, 28));
        btnExit.setText("退出");
        btnExit.addActionListener(new dlgVocation_btnExit_actionAdapter(this));
        btnDelete.setBounds(new Rectangle(132, 405, 76, 28));
        btnDelete.setText("删除");
        btnDelete.addActionListener(new dlgVocation_btnDelete_actionAdapter(this));
        btnUpdate.setBounds(new Rectangle(223, 367, 76, 28));
        btnUpdate.setText("更新");
        btnUpdate.addActionListener(new dlgVocation_btnUpdate_actionAdapter(this));
        btnSearch.setBounds(new Rectangle(19, 384, 97, 30));
        btnSearch.setText("模糊查询");
        btnSearch.addActionListener(new dlgVocation_btnSearch_actionAdapter(this));
        jScrollPane1.setBounds(new Rectangle(15, 13, 293, 300));
        this.getContentPane().add(btnDelete);
        this.getContentPane().add(btnExit);
        this.getContentPane().add(txtVocation);
        this.getContentPane().add(btnAdd);
        this.getContentPane().add(btnSearch);
        this.getContentPane().add(btnUpdate);
        this.getContentPane().add(jScrollPane1);
        this.setResizable(false);
        jScrollPane1.getViewport().add(tblDisplay);
        txtVocation.setText("");
        txtVocation.setBounds(new Rectangle(14, 324, 290, 32));
        vtColName.add("编号");
        vtColName.add("读者职业");
        DisplayAllVocation();
        //   tblDisplay.setAutoResizeMode(tblDisplay.AUTO_RESIZE_OFF);
        tblDisplay.getTableHeader().setReorderingAllowed(false);
    }

    //******************************显示所有读者职业********************************
     public void DisplayAllVocation() {
         VocationConDB VocationDB = new VocationConDB();
         vt = VocationDB.SearchAll();
         VocationDB.CloseVocationDB();
         dt = new DefaultTableModel(vt, vtColName);
         tblDisplay.setModel(dt);
     }

    //***************************查询同名读者职业***********************************
     public boolean SearchVocationName() {
         boolean SameName = false;
         Vector tempvt = new Vector();
         VocationConDB vocationDB = new VocationConDB();
         tempvt = vocationDB.SearchAll();
         vocationDB.CloseVocationDB();
         for (int i = 0; i < tempvt.size(); i++) {
             if (((Vector) (tempvt.get(i))).get(1).toString().equals(
                     txtVocation.
                     getText())) {
                 SameName = true;
             }
         }
         return SameName;
     }

    //*****************************显示窗口*********************************
     public void ShowVocation() {
         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 btnExit_actionPerformed(ActionEvent e) {
         this.dispose();
     }

    //*******************************查询按钮事件*******************************
     public void btnSearch_actionPerformed(ActionEvent e) {
         VocationConDB VocationDB = new VocationConDB();
         if (txtVocation.getText().equals("")) {
             JOptionPane.showMessageDialog(this, "请输入内容");
         } else {
             vt = VocationDB.SearchVocation(txtVocation.getText());
             VocationDB.CloseVocationDB();
             if (vt.size() < 1) {
                 dt = new DefaultTableModel(vt, vtColName);
                 tblDisplay.setModel(dt);
                 JOptionPane.showMessageDialog(this, "找不到记录!");
             } else {
                 dt = new DefaultTableModel(vt, vtColName);
                 tblDisplay.setModel(dt);
             }
         }
     }

    //*********************************添加按钮事件*****************************
     public void btnAdd_actionPerformed(ActionEvent e) {
         if (txtVocation.getText().equals(""))
             JOptionPane.showMessageDialog(this, "请输入一个出版社名称!");
         else {
             boolean SameName = SearchVocationName();
             if (SameName) {
                 JOptionPane.showMessageDialog(this, "存在同名的读者职业!");
                 return;
             }
             VocationConDB VocationDB = new VocationConDB();
             boolean Success;
             Success = VocationDB.AddVocation(txtVocation.getText());
             if (!Success) {
                 VocationDB.CloseVocationDB();
                 JOptionPane.showMessageDialog(this, "添加失败!");
                 return;
             }
             VocationDB.CloseVocationDB();
             DisplayAllVocation();
             JOptionPane.showMessageDialog(this, "出版社添加成功!");
         }
     }

    //********************************更新按钮事件******************************
     public void btnUpdate_actionPerformed(ActionEvent e) {
         if (tblDisplay.getSelectedRow() < 0) {
             JOptionPane.showMessageDialog(this, "请选择你要更新的出版社!");
         } else if (txtVocation.getText().equals("")) {
             JOptionPane.showMessageDialog(this, "请输入一个出版社名称!");
         } else {
             boolean SameName = SearchVocationName();
             if (SameName) {
                 JOptionPane.showMessageDialog(this, "存在同名的读者职业!");
                 return;
             }
             int Id = Integer.parseInt(tblDisplay.getValueAt(tblDisplay.
                     getSelectedRow(), 0).toString());
             VocationConDB VocationDB = new VocationConDB();
             boolean Success;
             Success = VocationDB.UpdateVocation(Id, txtVocation.getText());
             if (!Success) {
                 VocationDB.CloseVocationDB();
                 JOptionPane.showMessageDialog(this, "更新失败!");
                 return;
             }
             VocationDB.CloseVocationDB();
             DisplayAllVocation();
             JOptionPane.showMessageDialog(this, "出版社更新成功!");
         }
     }

    //**********************************删除按钮事件****************************
     public void btnDelete_actionPerformed(ActionEvent e) {
         if (tblDisplay.getSelectedRow() < 0) {
             JOptionPane.showMessageDialog(this, "请选择你要删除的出版社!");
         } else {
             int Id = Integer.parseInt(tblDisplay.getValueAt(tblDisplay.
                     getSelectedRow(), 0).toString());
             VocationConDB VocationDB = new VocationConDB();
             VocationDB.DeleteVocation(Id);
             VocationDB.CloseVocationDB();
             DisplayAllVocation();
             txtVocation.setText("");
             JOptionPane.showMessageDialog(this, "删除成功!");
         }
     }

    //*****************************鼠标点击表格事件*********************************
     public void tblDisplay_mouseClicked(MouseEvent e) {
         txtVocation.setText(tblDisplay.getValueAt(tblDisplay.getSelectedRow(),
                 1).toString());
     }
}


class dlgVocation_btnDelete_actionAdapter implements ActionListener {
    private dlgVocation adaptee;
    dlgVocation_btnDelete_actionAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgVocation_btnUpdate_actionAdapter implements ActionListener {
    private dlgVocation adaptee;
    dlgVocation_btnUpdate_actionAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgVocation_btnAdd_actionAdapter implements ActionListener {
    private dlgVocation adaptee;
    dlgVocation_btnAdd_actionAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgVocation_btnSearch_actionAdapter implements ActionListener {
    private dlgVocation adaptee;
    dlgVocation_btnSearch_actionAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

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


class dlgVocation_tblDisplay_mouseAdapter extends MouseAdapter {
    private dlgVocation adaptee;
    dlgVocation_tblDisplay_mouseAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tblDisplay_mouseClicked(e);
    }
}


class dlgVocation_btnExit_actionAdapter implements ActionListener {
    private dlgVocation adaptee;
    dlgVocation_btnExit_actionAdapter(dlgVocation adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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