Netbeans怀疑编译

时间:2011-05-01 13:33:30

标签: java netbeans compilation

我有一个在netbeans中创建的项目,当我编译它创建的类文件很好。但是如果我在编译后有一个名为operator.java的文件,我得到了operator.class,运算符$ 1.class,运算符$ 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个类。所以你选择负责制作plz的线路.. oz我在这段代码中没有使用任何内部类。我不确定Enum概念,所以如果你能帮助我,我可以从那里开始学习..

3 个答案:

答案 0 :(得分:3)

如果您的运算符类中包含内部类或枚举,那么在编译之后您将看到类似的额外类文件。


更新

您已经为侦听器使用了匿名类,并且它们都是作为名称运算符$ 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);
            }
        });
.......

答案 1 :(得分:3)

这不是特定于netbeans。

其他类文件是在operator.java内声明的匿名类的字节码,或者如果operator是一个声明每个实例方法定义的枚举,那么这些是由编译器通过这样的附加实现的gnerated课程。

修改

这是一个匿名类定义:

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

你的代码中有几个(MoustListener,ActionListener等) - 这是一种常见的习惯用法,就像那样内联地声明侦听器实现。

答案 2 :(得分:1)

operator.java必须包含内部类。