Netbeans对编译的疑问

发布于 2024-11-04 13:08:06 字数 10126 浏览 2 评论 0原文

我在 netbeans 中创建了一个项目,当我编译它时,它创建了类文件,这很好。但是,如果我有一个名为operator.java的文件,编译后我得到了operator.class、operator$1.class、operator$2.class等等。这样做有什么特殊原因吗?你能解释一下为什么会这样吗?

package admin;  
import forms_helper.global_variables;  
import java.sql.ResultSet;  
import java.sql.SQLException;  
import java.util.ArrayList;  
import java.util.List;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import utilities.mysql_query;  
import utilities.variables;  
public class stock_adjust extends javax.swing.JFrame {`  

    List<String> list = new ArrayList<String>();
    List<String> list_id = new ArrayList<String>();
    List<String> list_quantity = new ArrayList<String>();

    /** Creates new form stock_adjust */
    public stock_adjust() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        products = new javax.swing.JList();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel2 = new javax.swing.JLabel();
        product_name = new javax.swing.JTextField();
        qty = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cancel = new javax.swing.JButton();
        save = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Stock Adjust");
        setLocationByPlatform(true);
        setResizable(false);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Search:");

        jTextField1.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextField1CaretUpdate(evt);
            }
        });

        products.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productsMouseClicked(evt);
            }
        });
        products.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                productsValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(products);

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Adjust"));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Product Name:");
        jLabel2.setBounds(10, 30, 80, 20);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        product_name.setBounds(100, 30, 240, -1);
        jLayeredPane1.add(product_name, javax.swing.JLayeredPane.DEFAULT_LAYER);
        qty.setBounds(100, 60, 110, -1);
        jLayeredPane1.add(qty, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Quantity:");
        jLabel4.setBounds(10, 60, 80, 20);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cancel.setText("Cancel");
        cancel.setBounds(220, 110, -1, 30);
        jLayeredPane1.add(cancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        save.setText("Save");
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });
        save.setBounds(50, 110, 73, 30);
        jLayeredPane1.add(save, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton3.setText("Keyboard");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>                        

    private void jTextField1CaretUpdate(javax.swing.event.CaretEvent evt) {                                        
        try {
            String sql = "SELECT * FROM pos_products WHERE "
                    + "company_id='" + global_variables.company_id + "' AND "
                    + "shop_type='" + global_variables.shop_type + "' AND "
                    + "product_name LIKE '%" + jTextField1.getText() + "%' OR "
                    + "barcode LIKE '%" + jTextField1.getText() + "%'";

            list.removeAll(list);
            list_id.removeAll(list_id);
            list_quantity.removeAll(list_quantity);
            ResultSet rs = mysql_query.execute_mysql(variables.con.conn, sql);
            products.removeAll();
            while (rs.next()) {
                list.add(rs.getString("product_name"));
                list_id.add(rs.getString("p_id"));
                list_quantity.add(rs.getString("available_stock"));
            }
            products.setListData(list.toArray(new String[list.size()]));
        } catch (SQLException ex) {
            Logger.getLogger(stock_adjust.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                       

    private void productsValueChanged(javax.swing.event.ListSelectionEvent evt) {                                      
    }                                     

    private void productsMouseClicked(java.awt.event.MouseEvent evt) {                                      
        product_name.setText(list.get(products.getSelectedIndex()));
        qty.setText(list_quantity.get(products.getSelectedIndex()));
    }                                     

    private void saveActionPerformed(java.awt.event.ActionEvent evt) {                                     
        String sql = "UPDATE pos_products SET "
                + "available_stock='" + qty.getText() + "' WHERE "
                + "company_id='" + global_variables.company_id + "' AND "
                + "p_id='" + list_id.get(products.getSelectedIndex()) + "'";
        mysql_query.update_mysql(variables.con.conn, sql);
    }                                    

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new stock_adjust().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton cancel;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField product_name;
    private javax.swing.JList products;
    private javax.swing.JTextField qty;
    private javax.swing.JButton save;  }`

在上面的代码中我得到了 6 个这样的类。因此,您可以选择负责制作该代码的行。 oz 我在此代码中没有使用任何内部类。我不确定枚举概念,所以如果你能帮助我,我可以从那里开始学习..

I have a project created in netbeans and when i compiled it created class files which is fine. But if i have a file called operator.java after compiling i got operator.class, operator$1.class, operator$2.class and so on.. Is there any particular reason for doing it ? can you explain me why is it happening ?

package admin;  
import forms_helper.global_variables;  
import java.sql.ResultSet;  
import java.sql.SQLException;  
import java.util.ArrayList;  
import java.util.List;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import utilities.mysql_query;  
import utilities.variables;  
public class stock_adjust extends javax.swing.JFrame {`  

    List<String> list = new ArrayList<String>();
    List<String> list_id = new ArrayList<String>();
    List<String> list_quantity = new ArrayList<String>();

    /** Creates new form stock_adjust */
    public stock_adjust() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        products = new javax.swing.JList();
        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel2 = new javax.swing.JLabel();
        product_name = new javax.swing.JTextField();
        qty = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        cancel = new javax.swing.JButton();
        save = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Stock Adjust");
        setLocationByPlatform(true);
        setResizable(false);

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Search:");

        jTextField1.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jTextField1CaretUpdate(evt);
            }
        });

        products.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productsMouseClicked(evt);
            }
        });
        products.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                productsValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(products);

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Adjust"));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel2.setText("Product Name:");
        jLabel2.setBounds(10, 30, 80, 20);
        jLayeredPane1.add(jLabel2, javax.swing.JLayeredPane.DEFAULT_LAYER);
        product_name.setBounds(100, 30, 240, -1);
        jLayeredPane1.add(product_name, javax.swing.JLayeredPane.DEFAULT_LAYER);
        qty.setBounds(100, 60, 110, -1);
        jLayeredPane1.add(qty, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Quantity:");
        jLabel4.setBounds(10, 60, 80, 20);
        jLayeredPane1.add(jLabel4, javax.swing.JLayeredPane.DEFAULT_LAYER);

        cancel.setText("Cancel");
        cancel.setBounds(220, 110, -1, 30);
        jLayeredPane1.add(cancel, javax.swing.JLayeredPane.DEFAULT_LAYER);

        save.setText("Save");
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });
        save.setBounds(50, 110, 73, 30);
        jLayeredPane1.add(save, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton3.setText("Keyboard");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(19, 19, 19))
        );

        pack();
    }// </editor-fold>                        

    private void jTextField1CaretUpdate(javax.swing.event.CaretEvent evt) {                                        
        try {
            String sql = "SELECT * FROM pos_products WHERE "
                    + "company_id='" + global_variables.company_id + "' AND "
                    + "shop_type='" + global_variables.shop_type + "' AND "
                    + "product_name LIKE '%" + jTextField1.getText() + "%' OR "
                    + "barcode LIKE '%" + jTextField1.getText() + "%'";

            list.removeAll(list);
            list_id.removeAll(list_id);
            list_quantity.removeAll(list_quantity);
            ResultSet rs = mysql_query.execute_mysql(variables.con.conn, sql);
            products.removeAll();
            while (rs.next()) {
                list.add(rs.getString("product_name"));
                list_id.add(rs.getString("p_id"));
                list_quantity.add(rs.getString("available_stock"));
            }
            products.setListData(list.toArray(new String[list.size()]));
        } catch (SQLException ex) {
            Logger.getLogger(stock_adjust.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                       

    private void productsValueChanged(javax.swing.event.ListSelectionEvent evt) {                                      
    }                                     

    private void productsMouseClicked(java.awt.event.MouseEvent evt) {                                      
        product_name.setText(list.get(products.getSelectedIndex()));
        qty.setText(list_quantity.get(products.getSelectedIndex()));
    }                                     

    private void saveActionPerformed(java.awt.event.ActionEvent evt) {                                     
        String sql = "UPDATE pos_products SET "
                + "available_stock='" + qty.getText() + "' WHERE "
                + "company_id='" + global_variables.company_id + "' AND "
                + "p_id='" + list_id.get(products.getSelectedIndex()) + "'";
        mysql_query.update_mysql(variables.con.conn, sql);
    }                                    

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new stock_adjust().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton cancel;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField product_name;
    private javax.swing.JList products;
    private javax.swing.JTextField qty;
    private javax.swing.JButton save;  }`

In the above code i got 6 classes like that. So an you pick the lines responsible for making that plz.. oz i am not using any inner classes in this code. i am not sure about Enum concept so if you could help me out i can start learning from there..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱的十字路口 2024-11-11 13:08:06

这不是特定于 netbeans 的。

附加类文件是在 operator.java 中声明的匿名类的字节码,或者如果 operator 是声明每个实例方法定义的枚举,则这些文件由编译器也通过这些附加的生成类。

编辑:

这是一个匿名类定义:

new javax.swing.event.CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent evt) {
            jTextField1CaretUpdate(evt);
        }
    }

您的代码中有几个此类定义(MoustListener、ActionListener 等) - 像这样内联声明侦听器实现是一种常见的习惯用法。

This is not netbeans-specific.

The additional class files are the bytecode for either anonymous classes declared inside operator.java, or if operator is an enum that declared per-instance method definitions, then those are implemented by the compiler through such additional gnerated classes as well.

Edit:

This is an anonymous class definition:

new javax.swing.event.CaretListener() {
        public void caretUpdate(javax.swing.event.CaretEvent evt) {
            jTextField1CaretUpdate(evt);
        }
    }

You have several of those in your code (MoustListener, ActionListener, etc.) - it's a common idiom to declare listener implementations inline like that.

隐诗 2024-11-11 13:08:06

如果您的运算符类中有内部类或枚举,那么编译后您将看到像这样的额外类文件。


更新:

您已经为侦听器使用了匿名类,并且它们都被创建为名称 Operator$1.calss, .. 所以您会看到这么多类文件,因为您正在使用匿名为听众开设的课程。

.......
products.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productsMouseClicked(evt);
            }
        });
products.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                productsValueChanged(evt);
            }
        });
.......

If your operator class has inner classes or enums in it then after compilation you will see extra class file like this.


Update:

You have used anonymous classes for listeners and they all are created as a name Operator$1.calss, .. So you see this much class files because you are using anonymous classes for listeners.

.......
products.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                productsMouseClicked(evt);
            }
        });
products.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                productsValueChanged(evt);
            }
        });
.......
山色无中 2024-11-11 13:08:06

operator.java 内部必须有内部类。

operator.java must have inner classes inside.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文