Java Netbeans计算器错误

Java Netbeans计算器错误,java,swing,netbeans,Java,Swing,Netbeans,我用netbeans做了一个计算器,到目前为止,我添加了加号和减号按钮。但是假设我做5+5,它给我10,如果我再加5,它给我15。这样零件就正确了。但是如果我做9-5,它会给我-4,如果我从-4中减去2,我会得到正6。请帮忙,我对java相当陌生 public class Calculator extends javax.swing.JFrame { /** * Creates new form Calculator */ public Calculator() { initCom

我用netbeans做了一个计算器,到目前为止,我添加了加号和减号按钮。但是假设我做5+5,它给我10,如果我再加5,它给我15。这样零件就正确了。但是如果我做9-5,它会给我-4,如果我从-4中减去2,我会得到正6。请帮忙,我对java相当陌生

public class Calculator extends javax.swing.JFrame {

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

double fNums = 0.0;
double sNums = 0.0;
boolean add = false;
boolean sub = false;

/**
 * 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() {

    jPanel1 = new javax.swing.JPanel();
    display = new javax.swing.JTextField();
    seven = new javax.swing.JButton();
    eight = new javax.swing.JButton();
    nine = new javax.swing.JButton();
    plus = new javax.swing.JButton();
    four = new javax.swing.JButton();
    five = new javax.swing.JButton();
    six = new javax.swing.JButton();
    minus = new javax.swing.JButton();
    one = new javax.swing.JButton();
    two = new javax.swing.JButton();
    three = new javax.swing.JButton();
    multiply = new javax.swing.JButton();
    zero = new javax.swing.JButton();
    decimal = new javax.swing.JButton();
    divide = new javax.swing.JButton();
    enter = new javax.swing.JButton();
    clear = new javax.swing.JButton();
    jMenuBar2 = new javax.swing.JMenuBar();
    jMenu4 = new javax.swing.JMenu();
    Home = new javax.swing.JMenuItem();
    jMenu5 = new javax.swing.JMenu();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

    display.setEditable(false);

    seven.setText("7");
    seven.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            sevenActionPerformed(evt);
        }
    });

    eight.setText("8");
    eight.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            eightActionPerformed(evt);
        }
    });

    nine.setText("9");
    nine.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            nineActionPerformed(evt);
        }
    });

    plus.setText("+");
    plus.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            plusActionPerformed(evt);
        }
    });

    four.setText("4");
    four.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            fourActionPerformed(evt);
        }
    });

    five.setText("5");
    five.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            fiveActionPerformed(evt);
        }
    });

    six.setText("6");
    six.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            sixActionPerformed(evt);
        }
    });

    minus.setText("-");
    minus.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            minusActionPerformed(evt);
        }
    });

    one.setText("1");
    one.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            oneActionPerformed(evt);
        }
    });

    two.setText("2");
    two.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            twoActionPerformed(evt);
        }
    });

    three.setText("3");
    three.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            threeActionPerformed(evt);
        }
    });

    multiply.setText("*");
    multiply.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            multiplyActionPerformed(evt);
        }
    });

    zero.setText("0");
    zero.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            zeroActionPerformed(evt);
        }
    });

    decimal.setText(".");
    decimal.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            decimalActionPerformed(evt);
        }
    });

    divide.setText("/");
    divide.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            divideActionPerformed(evt);
        }
    });

    enter.setText("Enter");
    enter.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            enterActionPerformed(evt);
        }
    });

    clear.setText("C");
    clear.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            clearActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addGap(36, 36, 36)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(enter, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(one, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(two, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(three, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(multiply, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(four, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(five, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(six, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(minus, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(display)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(seven, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(nine, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(zero, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(divide, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    jPanel1Layout.setVerticalGroup(
        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel1Layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(18, 18, 18)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(seven, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(nine, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(four, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(five, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(six, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(minus, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(one, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(two, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(three, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(multiply, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(zero, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(divide, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(enter, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(54, Short.MAX_VALUE))
    );

    jMenu4.setText("File");

    Home.setText("Home");
    Home.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            HomeActionPerformed(evt);
        }
    });
    jMenu4.add(Home);

    jMenuBar2.add(jMenu4);

    jMenu5.setText("Edit");
    jMenuBar2.add(jMenu5);

    setJMenuBar(jMenuBar2);

    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()
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addContainerGap())
    );

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

private void HomeActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    Menu m = new Menu();
    m.setVisible(true);
}                                    

private void sixActionPerformed(java.awt.event.ActionEvent evt) {                                    
    // TODO add your handling code here:
    display.setText(display.getText() + six.getText());
}                                   

private void divideActionPerformed(java.awt.event.ActionEvent evt) {                                       
    // TODO add your handling code here:
    display.setText(display.getText() + divide.getText());
}                                      

private void sevenActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    display.setText(display.getText() + seven.getText());
}                                     

private void eightActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    display.setText(display.getText() + eight.getText());
}                                     

private void nineActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    display.setText(display.getText() + nine.getText());
}                                    

private void plusActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    fNums = fNums + Double.parseDouble(display.getText());   
    display.setText("");
    add = true;
}                                    

private void fourActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    display.setText(display.getText() + four.getText());
}                                    

private void fiveActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    display.setText(display.getText() + five.getText());
}                                    

private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    fNums = fNums - Double.parseDouble(display.getText()); 
    display.setText("");
    sub = true;
}                                     

private void oneActionPerformed(java.awt.event.ActionEvent evt) {                                    
    // TODO add your handling code here:
    display.setText(display.getText() + one.getText());
}                                   

private void twoActionPerformed(java.awt.event.ActionEvent evt) {                                    
    // TODO add your handling code here:
    display.setText(display.getText() + two.getText());
}                                   

private void threeActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    display.setText(display.getText() + three.getText());
}                                     

private void multiplyActionPerformed(java.awt.event.ActionEvent evt) {                                         
    // TODO add your handling code here:
    display.setText(display.getText() + multiply.getText());
}                                        

private void zeroActionPerformed(java.awt.event.ActionEvent evt) {                                     
    // TODO add your handling code here:
    display.setText(display.getText() + zero.getText());
}                                    

private void decimalActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    display.setText(display.getText() + decimal.getText());
}                                       

private void enterActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your enter code here:
    if(add = true){
    sNums = fNums + Double.parseDouble(display.getText());
    display.setText(String.valueOf(sNums));
    fNums = 0;
    add = false;
    } else {
    if(sub = true){
    sNums = fNums + Double.parseDouble(display.getText());
    display.setText(String.valueOf(sNums));
    fNums = 0;
    sub = false;
    }
    }
}                                     

private void clearActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    display.setText("");
    fNums = 0;
    sNums = 0;
}                                     

/**
 * @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 ("Windows".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(Calculator.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(Calculator.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() {
            new Calculator().setVisible(true);
        }
    });
}

// Variables declaration - do not modify                     
private javax.swing.JMenuItem Home;
private javax.swing.JButton clear;
private javax.swing.JButton decimal;
private javax.swing.JTextField display;
private javax.swing.JButton divide;
private javax.swing.JButton eight;
private javax.swing.JButton enter;
private javax.swing.JButton five;
private javax.swing.JButton four;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenuBar jMenuBar2;
private javax.swing.JPanel jPanel1;
private javax.swing.JButton minus;
private javax.swing.JButton multiply;
private javax.swing.JButton nine;
private javax.swing.JButton one;
private javax.swing.JButton plus;
private javax.swing.JButton seven;
private javax.swing.JButton six;
private javax.swing.JButton three;
private javax.swing.JButton two;
private javax.swing.JButton zero;
// End of variables declaration                   
}
公共类计算器扩展了javax.swing.JFrame{
/**
*创建新的表单计算器
*/
公共计算器(){
初始化组件();
}
双fNums=0.0;
双sNums=0.0;
布尔加法=假;
布尔子=假;
/**
*从构造函数中调用此方法来初始化表单。
*警告:不要修改此代码。此方法的内容始终为
*由表单编辑器重新生成。
*/
@抑制警告(“未选中”)
//                           
私有组件(){
jPanel1=newjavax.swing.JPanel();
display=newjavax.swing.JTextField();
seven=newjavax.swing.JButton();
八=新的javax.swing.JButton();
nine=newjavax.swing.JButton();
plus=newjavax.swing.JButton();
four=newjavax.swing.JButton();
five=newjavax.swing.JButton();
six=newjavax.swing.JButton();
减号=newjavax.swing.JButton();
one=newjavax.swing.JButton();
two=newjavax.swing.JButton();
three=newjavax.swing.JButton();
multiply=newjavax.swing.JButton();
zero=newjavax.swing.JButton();
decimal=newjavax.swing.JButton();
divide=newjavax.swing.JButton();
enter=newjavax.swing.JButton();
clear=newjavax.swing.JButton();
jMenuBar2=newjavax.swing.JMenuBar();
jMenu4=newjavax.swing.JMenu();
Home=newjavax.swing.JMenuItem();
jMenu5=newjavax.swing.JMenu();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE\u ON\u CLOSE);
display.setEditable(false);
七、setText(“7”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行了七次(evt);
}
});
八、setText(“8”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的八项测试(evt);
}
});
9.setText(“9”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行了9次(evt);
}
});
加上.setText(“+”);
plus.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的附加操作(evt);
}
});
四、setText(“4”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行四项操作(evt);
}
});
五、setText(“5”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的五项行动(evt);
}
});
6.setText(“6”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的六项操作(evt);
}
});
减.setText(“-”);
减去.addActionListener(新的java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的操作(evt);
}
});
一、setText(“1”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行一项行动(evt);
}
});
2.setText(“2”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行两项操作(evt);
}
});
三、setText(“3”);
addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行三项行动(evt);
}
});
multiply.setText(“*”);
multiply.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
多功能执行(evt);
}
});
0.setText(“0”);
zero.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行零动作(evt);
}
});
十进制.setText(“.”);
decimal.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行决策(evt);
}
});
除以.setText(“/”);
divide.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的分割操作(evt);
}
});
enter.setText(“enter”);
输入.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
已执行的交易(evt);
}
});
清楚。setText(“C”);
clear.addActionListener(新java.awt.event.ActionListener(){
public void actionPerformed(java.awt.event.ActionEvent evt){
执行的清除操作(evt);
}
});
javax.swing.GroupLayout jPanel1Layout=新的javax.swing.GroupLayout(jPanel1);
setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanellayout.createSequentialGroup()
.addGap(36,36,36)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,false)
.addGroup(javax.swing)。
 if(add == true){
    sNums = fNums + Double.parseDouble(display.getText());
    display.setText(String.valueOf(sNums));
    fNums = 0;
    add = false;
    } else {
    `
`if(sub == true){
    sNums = fNums + Double.parseDouble(display.getText());
    display.setText(String.valueOf(sNums));
    fNums = 0;
    sub = false;
    }
    }
private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                      
    // TODO add your handling code here:
    fNums = fNums - Double.parseDouble(display.getText()); 
    display.setText("");
    sub = true;
}        
private void minusActionPerformed(java.awt.event.ActionEvent evt) {                                      
// TODO add your handling code here:
fNums = Double.parseDouble(display.getText()); <----------
display.setText("");
sub = true;
private void enterActionPerformed(java.awt.event.ActionEvent evt) {                                      
// TODO add your enter code here:
if(add == true){
sNums = fNums + Double.parseDouble(display.getText());
display.setText(String.valueOf(sNums));
fNums = 0;
add = false;
} else {
if(sub == true){
sNums = fNums - Double.parseDouble(display.getText());   <----------
display.setText(String.valueOf(sNums));
fNums = 0;
sub = false;
}
}