/*
 * Created by JFormDesigner on Wed Mar 12 16:06:47 CST 2025
 */

package gui.UI_LenheartUI;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.MouseInputAdapter;
import javax.swing.table.*;
import com.intellij.uiDesigner.core.*;
import com.jgoodies.forms.factories.*;
import com.jgoodies.forms.layout.*;
import database.DBConPool;
import gui.tw.Drop;
import info.clearthought.layout.*;
import net.miginfocom.swing.*;
import server.MapleItemInformationProvider;
import server.life.MapleLifeFactory;
import tools.FileoutputUtil;

/**
 * @author dongj
 */
public class ExplosiveControl extends JPanel {
    public ExplosiveControl() {
        initComponents();
    }

    public void ClearTable(JTable tableobj) {
        for (int i = ((DefaultTableModel) (DefaultTableModel) tableobj.getModel()).getRowCount() - 1; i >= 0; --i) {
            ((DefaultTableModel) (DefaultTableModel) tableobj.getModel()).removeRow(i);
        }
    }

    public void WriteTable2(List<Drop> kps){
        DefaultTableModel tableModel = (DefaultTableModel)table2.getModel();

        for (Drop kp : kps) {
            tableModel.insertRow(this.table2.getRowCount(), new Object[]{Integer.valueOf(kp.getId()), kp.getDropName(), Integer.valueOf(kp.getDropperid()), kp.getItenName(), Integer.valueOf(kp.getItemId()), Integer.valueOf(kp.getChance())});
        }
    }

    public void WriteTable1(List<Drop> kps){
        DefaultTableModel tableModel = (DefaultTableModel)table1.getModel();

        for (Drop kp : kps) {
            tableModel.insertRow(this.table1.getRowCount(), new Object[]{Integer.valueOf(kp.getId()), kp.getItenName(), Integer.valueOf(kp.getItemId()), Integer.valueOf(kp.getChance())});
        }
    }


    private void 加载刷新怪物卡片(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getKPS());
    }

    private void 刷新怪物爆物数据(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getMobBLs());

        ClearTable(table1);
        WriteTable1(Drop.getQQS());
    }

    private void 根据怪物ID清理(ActionEvent e) {
        Drop.deleteGWdropperid(Integer.valueOf(this.怪物ID清理.getText()));
        ClearTable(table2);
        刷新怪物爆物数据(null);
    }

    private void 根据物品ID清理(ActionEvent e) {
        Drop.deleteItemId(Integer.valueOf(this.物品ID清理.getText()));
        ClearTable(table1);
        ClearTable(table2);
        刷新怪物爆物数据(null);
    }

    private void 一键清空独立爆率表(ActionEvent e) {
        Drop.deleteGWAll();
        ClearTable(table2);
    }

    private void 一键清空全局爆率表(ActionEvent e) {
        Drop.deleteQJAll();
        ClearTable(table1);
    }

    private void button物品ID查询掉落(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getItemIdsMob(this.物品ID查询掉落.getText()));
    }

    private void 物品名查询掉落函数(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getItemNamesMob(this.物品名查询掉落.getText()));
    }

    private void 怪物ID查询掉落函数(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getMobIdsMob(this.怪物ID查询掉落.getText()));
    }

    private void 怪物名查询掉落函数(ActionEvent e) {
        ClearTable(table2);
        WriteTable2(Drop.getMobNames(this.怪物名查询掉落.getText()));
    }

    public void SetRightL(JTable tableobj){
        DefaultTableModel tableModel = (DefaultTableModel)tableobj.getModel();
        
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        
        for (int i = 0; i < tableobj.getColumnCount(); i++) {
            if (tableobj.getColumnClass(i) == String.class) {
                tableobj.getColumnModel().getColumn(i).setCellRenderer(rightRenderer);
            }
        }
    }

    private void 新增独立爆率配置(ActionEvent e) {
        Integer MonId;
        Integer ItemId;
        Integer Chance;
        try {
            MonId = Integer.valueOf(this.G_1.getText());
            ItemId = Integer.valueOf(this.G_2.getText());
            Chance = Integer.valueOf(this.G_3.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "新增失败！检查是否填写了全部参数", "提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }


        try {
            Drop.insertGWId(MonId, ItemId, Chance);
        } catch (Exception ee) {
            
            JOptionPane.showMessageDialog(null, "新增失败！检查怪物ID和物品ID是否有误。", "提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        刷新怪物爆物数据(null);
    }

    private void 独立爆率删除配置(ActionEvent e) {
        
        int selectedRow = table2.getSelectedRow();
        if (selectedRow != -1) {
            DefaultTableModel tableModel = (DefaultTableModel) table2.getModel();
            Integer Ids = (Integer) tableModel.getValueAt(selectedRow,0);
            Integer MonId = (Integer) tableModel.getValueAt(selectedRow,2);
            Drop.deleteGWId(Ids,MonId);
            tableModel.removeRow(selectedRow);
            if(tableModel.getRowCount() > selectedRow)table2.setRowSelectionInterval(selectedRow, selectedRow);
        }
    }

    private void 新增全局爆率配置(ActionEvent e) {
        Integer ItemId;
        Integer Chance;
        try {
            ItemId = Integer.valueOf(this.G_5.getText());
            Chance = Integer.valueOf(this.G_6.getText());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "新增失败！检查是否填写了全部参数", "提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }


        try {
            Drop.insertQQ( ItemId, Chance);
        } catch (Exception ee) {
            
            JOptionPane.showMessageDialog(null, "新增失败！检查怪物ID和物品ID是否有误。", "提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }

        刷新怪物爆物数据(null);
    }

    private void 删除全局爆率配置(ActionEvent e) {
        int selectedRow = table1.getSelectedRow();
        if (selectedRow != -1) {
            DefaultTableModel tableModel = (DefaultTableModel) table1.getModel();
            Integer Ids = (Integer) tableModel.getValueAt(selectedRow,0);
            Integer MonId = (Integer) tableModel.getValueAt(selectedRow,2);
            
            tableModel.removeRow(selectedRow);
            if(tableModel.getRowCount() > selectedRow)table1.setRowSelectionInterval(selectedRow, selectedRow);
        }
    }

    private void 独立爆率一键导入(ActionEvent e) {
        
        JFileChooser fileChooser = new JFileChooser();

        
        int result = fileChooser.showOpenDialog(null);

        
        if (result == JFileChooser.APPROVE_OPTION) {
            
            File selectedFile = fileChooser.getSelectedFile();
            Drop.importDataMob(selectedFile.getAbsolutePath());
        }
    }

    private void 独立爆率一键导出(ActionEvent e) {
        
        JFileChooser folderChooser = new JFileChooser();
        
        folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        
        JRadioButton option1 = new JRadioButton("卡片");
        JRadioButton option2 = new JRadioButton("怪物");
        
        ButtonGroup buttonGroup = new ButtonGroup();
        buttonGroup.add(option1);
        buttonGroup.add(option2);
        
        option1.setSelected(true);

        
        JPanel optionPanel = new JPanel();
        optionPanel.add(option1);
        optionPanel.add(option2);

        
        folderChooser.setAccessory(optionPanel);

        
        int result = folderChooser.showOpenDialog(null);

        
        if (result == JFileChooser.APPROVE_OPTION) {
            
            File selectedFolder = folderChooser.getSelectedFile();
            String selectedMode = option1.isSelected() ? "卡片" : "怪物";
            
            Drop.exportData(selectedFolder.getAbsolutePath() + "/独立爆率" + selectedMode + ".txt", selectedMode.equals("卡片") ? Drop.getKPS(): Drop.getMobBLs());
        }
    }

    private void 全局爆率一键导出(ActionEvent e) {
        
        JFileChooser folderChooser = new JFileChooser();
        
        folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

        
        int result = folderChooser.showOpenDialog(null);

        
        if (result == JFileChooser.APPROVE_OPTION) {
            
            File selectedFolder = folderChooser.getSelectedFile();
            Drop.exportData(selectedFolder.getAbsolutePath().toString() + "/全局爆率.txt",Drop.getQQS());
        }
    }

    private void 全局爆率一键导入(ActionEvent e) {
        
        JFileChooser fileChooser = new JFileChooser();

        
        int result = fileChooser.showOpenDialog(null);

        
        if (result == JFileChooser.APPROVE_OPTION) {
            
            File selectedFile = fileChooser.getSelectedFile();
            Drop.importDataQQ(selectedFile.getAbsolutePath());
        }
    }




    private void initComponents() {
        
        panel1 = new JPanel();
        button9 = new JButton();
        button10 = new JButton();
        panel2 = new JPanel();
        button11 = new JButton();
        panel3 = new JPanel();
        怪物ID清理 = new JTextField();
        物品ID清理 = new JTextField();
        button13 = new JButton();
        button14 = new JButton();
        label5 = new JLabel();
        label6 = new JLabel();
        panel4 = new JPanel();
        物品ID查询掉落 = new JTextField();
        button15 = new JButton();
        物品名查询掉落 = new JTextField();
        button16 = new JButton();
        怪物ID查询掉落 = new JTextField();
        button17 = new JButton();
        怪物名查询掉落 = new JTextField();
        button18 = new JButton();
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        label4 = new JLabel();
        panel5 = new JPanel();
        scrollPane3 = new JScrollPane();
        table2 = new JTable();
        panel6 = new JPanel();
        scrollPane1 = new JScrollPane();
        table1 = new JTable();
        button1 = new JButton();
        button2 = new JButton();
        button5 = new JButton();
        button6 = new JButton();
        button3 = new JButton();
        button4 = new JButton();
        button7 = new JButton();
        button8 = new JButton();
        button19 = new JButton();
        G_1 = new JTextField();
        G_2 = new JTextField();
        G_3 = new JTextField();
        label7 = new JLabel();
        label8 = new JLabel();
        label9 = new JLabel();
        label11 = new JLabel();
        G_5 = new JTextField();
        label12 = new JLabel();
        G_6 = new JTextField();

        
        setLayout(null);

        
        {
            panel1.setBorder(new TitledBorder("\u5371\u9669\u64cd\u4f5c"));
            panel1.setLayout(null);

            
            button9.setText("\u4e00\u952e\u6e05\u7a7a\u72ec\u7acb\u7206\u7387\u8868");
            button9.addActionListener(e -> 一键清空独立爆率表(e));
            panel1.add(button9);
            button9.setBounds(5, 30, 190, button9.getPreferredSize().height);

            
            button10.setText("\u4e00\u952e\u6e05\u7a7a\u5168\u5c40\u7206\u7387\u8868");
            button10.addActionListener(e -> 一键清空全局爆率表(e));
            panel1.add(button10);
            button10.setBounds(5, 60, 190, button10.getPreferredSize().height);

            {
                
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel1.getComponentCount(); i++) {
                    Rectangle bounds = panel1.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel1.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel1.setMinimumSize(preferredSize);
                panel1.setPreferredSize(preferredSize);
            }
        }
        add(panel1);
        panel1.setBounds(25, 5, 200, 105);

        
        {
            panel2.setBorder(new TitledBorder("\u602a\u7269\u5361\u7247"));
            panel2.setLayout(null);

            
            button11.setText("\u52a0\u8f7d\u5237\u65b0\u602a\u7269\u5361\u7247");
            button11.addActionListener(e -> 加载刷新怪物卡片(e));
            panel2.add(button11);
            button11.setBounds(5, 19, 190, button11.getPreferredSize().height);

            {
                
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel2.getComponentCount(); i++) {
                    Rectangle bounds = panel2.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel2.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel2.setMinimumSize(preferredSize);
                panel2.setPreferredSize(preferredSize);
            }
        }
        add(panel2);
        panel2.setBounds(25, 120, 200, 65);

        
        {
            panel3.setBorder(new TitledBorder("\u5feb\u6377\u6e05\u7406\u6240\u6709\u7206\u7387"));
            panel3.setLayout(null);
            panel3.add(怪物ID清理);
            怪物ID清理.setBounds(10, 35, 115, 怪物ID清理.getPreferredSize().height);
            panel3.add(物品ID清理);
            物品ID清理.setBounds(10, 85, 115, 物品ID清理.getPreferredSize().height);

            
            button13.setText("\u6e05\u7406");
            button13.addActionListener(e -> 根据怪物ID清理(e));
            panel3.add(button13);
            button13.setBounds(130, 35, 58, 25);

            
            button14.setText("\u6e05\u7406");
            button14.addActionListener(e -> 根据物品ID清理(e));
            panel3.add(button14);
            button14.setBounds(130, 85, 58, 25);

            
            label5.setText("\u6839\u636e\u602a\u7269ID\u6e05\u7406");
            panel3.add(label5);
            label5.setBounds(15, 20, 85, 17);

            
            label6.setText("\u6839\u636e\u7269\u54c1ID\u6e05\u7406");
            panel3.add(label6);
            label6.setBounds(15, 70, 85, 17);

            {
                
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel3.getComponentCount(); i++) {
                    Rectangle bounds = panel3.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel3.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel3.setMinimumSize(preferredSize);
                panel3.setPreferredSize(preferredSize);
            }
        }
        add(panel3);
        panel3.setBounds(25, 200, 200, 125);

        
        {
            panel4.setBorder(new TitledBorder("\u5feb\u6377\u67e5\u8be2"));
            panel4.setLayout(null);
            panel4.add(物品ID查询掉落);
            物品ID查询掉落.setBounds(10, 40, 115, 物品ID查询掉落.getPreferredSize().height);

            
            button15.setText("\u67e5\u8be2");
            button15.addActionListener(e -> button物品ID查询掉落(e));
            panel4.add(button15);
            button15.setBounds(130, 40, 58, 25);
            panel4.add(物品名查询掉落);
            物品名查询掉落.setBounds(10, 90, 115, 物品名查询掉落.getPreferredSize().height);

            
            button16.setText("\u67e5\u8be2");
            button16.addActionListener(e -> 物品名查询掉落函数(e));
            panel4.add(button16);
            button16.setBounds(130, 90, 58, 25);
            panel4.add(怪物ID查询掉落);
            怪物ID查询掉落.setBounds(10, 140, 115, 怪物ID查询掉落.getPreferredSize().height);

            
            button17.setText("\u67e5\u8be2");
            button17.addActionListener(e -> 怪物ID查询掉落函数(e));
            panel4.add(button17);
            button17.setBounds(130, 140, 58, 25);
            panel4.add(怪物名查询掉落);
            怪物名查询掉落.setBounds(10, 190, 115, 怪物名查询掉落.getPreferredSize().height);

            
            button18.setText("\u67e5\u8be2");
            button18.addActionListener(e -> 怪物名查询掉落函数(e));
            panel4.add(button18);
            button18.setBounds(130, 190, 58, 25);

            
            label1.setText("\u7269\u54c1ID\u67e5\u8be2\u6389\u843d");
            panel4.add(label1);
            label1.setBounds(new Rectangle(new Point(15, 25), label1.getPreferredSize()));

            
            label2.setText("\u7269\u54c1\u540d\u67e5\u8be2\u6389\u843d");
            panel4.add(label2);
            label2.setBounds(15, 75, 85, 17);

            
            label3.setText("\u602a\u7269ID\u67e5\u8be2\u6389\u843d");
            panel4.add(label3);
            label3.setBounds(15, 125, 85, 17);

            
            label4.setText("\u602a\u7269\u540d\u67e5\u8be2\u6389\u843d");
            panel4.add(label4);
            label4.setBounds(15, 175, 85, 17);

            {
                
                Dimension preferredSize = new Dimension();
                for(int i = 0; i < panel4.getComponentCount(); i++) {
                    Rectangle bounds = panel4.getComponent(i).getBounds();
                    preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                    preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
                }
                Insets insets = panel4.getInsets();
                preferredSize.width += insets.right;
                preferredSize.height += insets.bottom;
                panel4.setMinimumSize(preferredSize);
                panel4.setPreferredSize(preferredSize);
            }
        }
        add(panel4);
        panel4.setBounds(25, 340, 200, 235);

        
        {
            panel5.setBorder(new TitledBorder("\u602a\u7269\u72ec\u7acb\u7206\u7387"));
            panel5.setLayout(new GridLayout());

            
            {

                
                table2.setModel(new DefaultTableModel(
                    new Object[][] {
                    },
                    new String[] {
                        "\u5e8f\u53f7", "\u602a\u7269\u540d", "\u602a\u7269ID", "\u7269\u54c1\u540d", "\u7269\u54c1ID", "\u7206\u7387"
                    }
                ) {
                    Class<?>[] columnTypes = new Class<?>[] {
                        Integer.class, String.class, Integer.class, String.class, Integer.class, Integer.class
                    };
                    @Override
                    public Class<?> getColumnClass(int columnIndex) {
                        return columnTypes[columnIndex];
                    }
                });
                {
                    TableColumnModel cm = table2.getColumnModel();
                    cm.getColumn(1).setMinWidth(180);
                    cm.getColumn(3).setMinWidth(180);
                }
                scrollPane3.setViewportView(table2);
            }
            panel5.add(scrollPane3);
        }
        add(panel5);
        panel5.setBounds(235, 5, 840, 580);

        
        {
            panel6.setBorder(new TitledBorder("\u5168\u5c40\u7206\u7387"));
            panel6.setLayout(new GridLayout());

            
            {

                
                table1.setModel(new DefaultTableModel(
                    new Object[][] {
                    },
                    new String[] {
                        "\u5e8f\u53f7", "\u7269\u54c1\u540d", "\u7269\u54c1ID", "\u7206\u7387"
                    }
                ) {
                    Class<?>[] columnTypes = new Class<?>[] {
                        Integer.class, String.class, Integer.class, Integer.class
                    };
                    @Override
                    public Class<?> getColumnClass(int columnIndex) {
                        return columnTypes[columnIndex];
                    }
                });
                {
                    TableColumnModel cm = table1.getColumnModel();
                    cm.getColumn(0).setMaxWidth(50);
                    cm.getColumn(1).setMinWidth(150);
                }
                scrollPane1.setViewportView(table1);
            }
            panel6.add(scrollPane1);
        }
        add(panel6);
        panel6.setBounds(1080, 5, 410, 580);

        
        button1.setText("\u65b0\u589e\u914d\u7f6e");
        button1.addActionListener(e -> 新增独立爆率配置(e));
        add(button1);
        button1.setBounds(235, 625, 95, button1.getPreferredSize().height);

        
        button2.setText("\u5220\u9664\u914d\u7f6e");
        button2.addActionListener(e -> 独立爆率删除配置(e));
        add(button2);
        button2.setBounds(345, 625, 95, 34);

        
        button5.setText("\u4e00\u952e\u5bfc\u5165");
        button5.addActionListener(e -> 独立爆率一键导入(e));
        add(button5);
        button5.setBounds(455, 625, 95, 34);

        
        button6.setText("\u4e00\u952e\u5bfc\u51fa");
        button6.addActionListener(e -> 独立爆率一键导出(e));
        add(button6);
        button6.setBounds(560, 625, 95, 34);

        
        button3.setText("\u65b0\u589e\u914d\u7f6e");
        button3.addActionListener(e -> 新增全局爆率配置(e));
        add(button3);
        button3.setBounds(1080, 625, 95, 34);

        
        button4.setText("\u5220\u9664\u914d\u7f6e");
        button4.addActionListener(e -> 删除全局爆率配置(e));
        add(button4);
        button4.setBounds(1185, 625, 95, 34);

        
        button7.setText("\u4e00\u952e\u5bfc\u5165");
        button7.addActionListener(e -> 全局爆率一键导入(e));
        add(button7);
        button7.setBounds(1290, 625, 95, 34);

        
        button8.setText("\u4e00\u952e\u5bfc\u51fa");
        button8.addActionListener(e -> 全局爆率一键导出(e));
        add(button8);
        button8.setBounds(1395, 625, 95, 34);

        
        button19.setText("\u5237\u65b0\u602a\u7269\u7206\u7269\u6570\u636e");
        button19.addActionListener(e -> 刷新怪物爆物数据(e));
        add(button19);
        button19.setBounds(45, 585, 155, 60);

        
        G_1.setToolTipText("\u602a\u7269ID");
        add(G_1);
        G_1.setBounds(280, 590, 100, 30);

        
        G_2.setToolTipText("\u7269\u54c1ID");
        add(G_2);
        G_2.setBounds(425, 590, 100, 30);

        
        G_3.setToolTipText("\u7206\u7387");
        add(G_3);
        G_3.setBounds(560, 590, 100, 30);

        
        label7.setText("\u602a\u7269ID");
        add(label7);
        label7.setBounds(new Rectangle(new Point(240, 595), label7.getPreferredSize()));

        
        label8.setText("\u7269\u54c1ID");
        add(label8);
        label8.setBounds(385, 595, 37, 17);

        
        label9.setText("\u7206\u7387");
        add(label9);
        label9.setBounds(530, 595, 37, 17);

        
        label11.setText("\u7269\u54c1ID");
        add(label11);
        label11.setBounds(1085, 595, 37, 17);

        
        G_5.setToolTipText("\u7269\u54c1ID");
        add(G_5);
        G_5.setBounds(1125, 590, 100, 30);

        
        label12.setText("\u7206\u7387");
        add(label12);
        label12.setBounds(1230, 595, 37, 17);

        
        G_6.setToolTipText("\u7206\u7387");
        add(G_6);
        G_6.setBounds(1260, 590, 100, 30);

        {
            
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < getComponentCount(); i++) {
                Rectangle bounds = getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            setMinimumSize(preferredSize);
            setPreferredSize(preferredSize);
        }
        

        SetRightL(this.table1);
        SetRightL(this.table2);

        DefaultTableModel tableModel = (DefaultTableModel) table2.getModel();
        
        TableRowSorter<DefaultTableModel> sorter = new TableRowSorter<>(tableModel);
        table2.setRowSorter(sorter);

        DefaultTableModel tableModel1 = (DefaultTableModel) table1.getModel();
        
        TableRowSorter<DefaultTableModel> sorter1 = new TableRowSorter<>(tableModel1);
        table1.setRowSorter(sorter1);

        
        table2.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                
                int row = table2.rowAtPoint(e.getPoint());

                if (row >= 0) {
                    
                    Object MonId = table2.getValueAt(row, 2);
                    Object ItemId = table2.getValueAt(row, 4);
                    Object Chance = table2.getValueAt(row, 5);

                    G_1.setText(MonId.toString());
                    G_2.setText(ItemId.toString());
                    G_3.setText(Chance.toString());
                }
            }
        });

        table1.addMouseListener(new MouseInputAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                
                int row = table1.rowAtPoint(e.getPoint());

                if (row >= 0) {
                    
                    Object ItemId = table1.getValueAt(row, 2);
                    Object Chance = table1.getValueAt(row, 3);

                    G_5.setText(ItemId.toString());
                    G_6.setText(Chance.toString());
                }
            }
        });
    }

    
    private JPanel panel1;
    private JButton button9;
    private JButton button10;
    private JPanel panel2;
    private JButton button11;
    private JPanel panel3;
    private JTextField 怪物ID清理;
    private JTextField 物品ID清理;
    private JButton button13;
    private JButton button14;
    private JLabel label5;
    private JLabel label6;
    private JPanel panel4;
    private JTextField 物品ID查询掉落;
    private JButton button15;
    private JTextField 物品名查询掉落;
    private JButton button16;
    private JTextField 怪物ID查询掉落;
    private JButton button17;
    private JTextField 怪物名查询掉落;
    private JButton button18;
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JLabel label4;
    private JPanel panel5;
    private JScrollPane scrollPane3;
    private JTable table2;
    private JPanel panel6;
    private JScrollPane scrollPane1;
    private JTable table1;
    private JButton button1;
    private JButton button2;
    private JButton button5;
    private JButton button6;
    private JButton button3;
    private JButton button4;
    private JButton button7;
    private JButton button8;
    private JButton button19;
    private JTextField G_1;
    private JTextField G_2;
    private JTextField G_3;
    private JLabel label7;
    private JLabel label8;
    private JLabel label9;
    private JLabel label11;
    private JTextField G_5;
    private JLabel label12;
    private JTextField G_6;
    
}
