Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/401.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 导入语句代码错误_Java - Fatal编程技术网

Java 导入语句代码错误

Java 导入语句代码错误,java,Java,好的,首先我正在处理的项目有两个包,第一个是murach.business,它包含invoiceCalculations.java 第二个是murach.forms,它包含InvoiceForm.java(JFrame)和SwingValidator.java 因此,我应该为我从头创建的Invoiceformjava中的murach.business.InvoiceCalculations和java.text.NumberFormat类添加add导入语句 但是,当我编写代码时,会出现错误。net

好的,首先我正在处理的项目有两个包,第一个是murach.business,它包含invoiceCalculations.java 第二个是murach.forms,它包含InvoiceForm.java(JFrame)和SwingValidator.java

因此,我应该为我从头创建的Invoiceformjava中的murach.business.InvoiceCalculations和java.text.NumberFormat类添加add导入语句

但是,当我编写代码时,会出现错误。netbeans表示未使用的代码

我的代码不正确吗?怎么了?请往正确的方向推

/*
  * To change this template, choose Tools | Templates
* and open the template in the editor.
*/

 package murach.forms;
 import murach.business.InvoiceCalculations;
 import java.text.NumberFormat;


 /**
   *
   * @author james
   */
 public class InvoiceForm extends javax.swing.JFrame {

/**
 * Creates new form InvoiceForm
 */
public InvoiceForm() {
    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() {

    messageLabe1 = new javax.swing.JLabel();
    messageLabe2 = new javax.swing.JLabel();
    messageLabe3 = new javax.swing.JLabel();
    messageLabe4 = new javax.swing.JLabel();
    messageLabe5 = new javax.swing.JLabel();
    customertypeTextField = new javax.swing.JTextField();
    subtotalTextField = new javax.swing.JTextField();
    discountpercentTextField = new javax.swing.JTextField();
    discountamountTextField = new javax.swing.JTextField();
    totalTextField = new javax.swing.JTextField();
    calculateButton = new javax.swing.JButton();
    exitButton = new javax.swing.JButton();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Invoice Total Calculator");

    messageLabe1.setText("Customer Type:");

    messageLabe2.setText("Subtotal:");

    messageLabe3.setText("Discount Percent:");

    messageLabe4.setText("Discount Amount:");

    messageLabe5.setText("Total:");

    customertypeTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            customertypeTextFieldActionPerformed(evt);
        }
    });

    subtotalTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            subtotalTextFieldActionPerformed(evt);
        }
    });

    discountpercentTextField.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            discountpercentTextFieldActionPerformed(evt);
        }
    });

    calculateButton.setMnemonic('c');
    calculateButton.setText("Calculate");
    calculateButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            calculateButtonActionPerformed(evt);
        }
    });

    exitButton.setMnemonic('x');
    exitButton.setText("Exit");
    exitButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitButtonActionPerformed(evt);
        }
    });

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(38, 38, 38)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(messageLabe1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(messageLabe2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(messageLabe3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 126, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(messageLabe4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 137, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(messageLabe5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(totalTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                    .add(discountamountTextField))
                .add(org.jdesktop.layout.GroupLayout.TRAILING, discountpercentTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(customertypeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(subtotalTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(74, Short.MAX_VALUE))
        .add(layout.createSequentialGroup()
            .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .add(calculateButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(exitButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(43, 43, 43))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(layout.createSequentialGroup()
            .add(31, 31, 31)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(messageLabe1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(customertypeTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(messageLabe2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(subtotalTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(6, 6, 6)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(messageLabe3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(discountpercentTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(6, 6, 6)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(messageLabe4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(discountamountTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(6, 6, 6)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(messageLabe5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(totalTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(18, 18, 18)
            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                .add(exitButton)
                .add(calculateButton))
            .addContainerGap(58, Short.MAX_VALUE))
    );

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

private void customertypeTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                      
    // TODO add your handling code here:

}                                                     

private void subtotalTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    // TODO add your handling code here:
}                                                 

private void exitButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
       // TODO add your handling code here:
    exitButton.addActionListener(new java.awt.event.ActionListener(){
        @Override
           public void actionPerformed(java.awt.event.ActionEvent evt) {
               exitButtonActionPerformed (evt);
           }
    });
}                                          

private void calculateButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                
      // TODO add your handling code here:
   double c = Double.parseDouble(customertypeTextField.getText());
   double s = Double.parseDouble(subtotalTextField.getText());
   double d = Double.parseDouble(discountpercentTextField.getText());

}                                               

private void discountpercentTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                                         
    // TODO add your handling code here:

}                                                        

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(InvoiceForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(InvoiceForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(InvoiceForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(InvoiceForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            InvoiceForm frame  =new InvoiceForm();
            frame.setVisible (true);
            frame.setLocationRelativeTo(null);
        }
    });
}
// Variables declaration - do not modify                     
private javax.swing.JButton calculateButton;
private javax.swing.JTextField customertypeTextField;
private javax.swing.JTextField discountamountTextField;
private javax.swing.JTextField discountpercentTextField;
private javax.swing.JButton exitButton;
private javax.swing.JLabel messageLabe1;
private javax.swing.JLabel messageLabe2;
private javax.swing.JLabel messageLabe3;
private javax.swing.JLabel messageLabe4;
private javax.swing.JLabel messageLabe5;
private javax.swing.JTextField subtotalTextField;
private javax.swing.JTextField totalTextField;
// End of variables declaration                   
 }
/*
*要更改此模板,请选择工具|模板
*然后在编辑器中打开模板。
*/
包装murach.forms;
导入murach.business.InvoiceCalculations;
导入java.text.NumberFormat;
/**
*
*@作者詹姆斯
*/
公共类InvoiceForm扩展了javax.swing.JFrame{
/**
*创建新表单InvoiceForm
*/
公共发票表格(){
初始化组件();
}
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//                           
私有组件(){
messageLabe1=newjavax.swing.JLabel();
messageLabe2=newjavax.swing.JLabel();
messageLabe3=newjavax.swing.JLabel();
messageLabe4=newjavax.swing.JLabel();
messageLabe5=newjavax.swing.JLabel();
customertypeTextField=newjavax.swing.JTextField();
subtotalTextField=newjavax.swing.JTextField();
discountpercentTextField=newjavax.swing.JTextField();
discountamountTextField=newjavax.swing.JTextField();
totalTextField=newjavax.swing.JTextField();
calculateButton=newjavax.swing.JButton();
exitButton=newjavax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“发票总额计算器”);
messageLabe1.setText(“客户类型:”);
messageLabe2.setText(“小计:”);
messageLabe3.setText(“折扣百分比:”);
messageLabe4.setText(“折扣金额:”);
messagelab5.setText(“总计:”);
customertypeTextField.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
customertypeTextFieldActionPerformed(evt);
}
});
subtotalTextField.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作小计(evt);
}
});
discountpercentTextField.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
折扣百分比TextFieldActionPerformed(evt);
}
});
calculateButton.setMemonic('c');
calculateButton.setText(“计算”);
calculateButton.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的计算按钮操作(evt);
}
});
exitButton.set助记符('x');
setText(“退出”);
exitButton.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
ExitButtoActionExecuted(evt);
}
});
org.jdesktop.layout.GroupLayout=new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(布局);
layout.setHorizontalGroup(
createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.增补(38、38、38)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(messageLabe1,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE,100,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE)
.add(messageLabe2,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE,100,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE)
.add(messageLabe3,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE,126,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE)
.add(messageLabe4,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE,137,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE)
.add(messageLabe5,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,100,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,false)
.add(totalTextField,org.jdesktop.layout.GroupLayout.DEFAULT\u SIZE,145,Short.MAX\u值)
.add(折扣装入文本字段))
.add(org.jdesktop.layout.GroupLayout.TRAILING,折扣百分比文本字段,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE,144,org.jdesktop.layout.GroupLayout.PREFERRED\u SIZE)
.add(org.jdesktop.layout.GroupLayout.TRAILING,layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(customertypeTextField,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,40,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(小计文本字段,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,144,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(74,简称最大值))
.add(layout.createSequentialGroup()
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE)
.add(calculateButton,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,124,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(exitButton,org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,77,