Netbeans GUI的运行按钮显示为灰色

时间:2014-11-02 16:48:54

标签: java user-interface netbeans netbeans-8

Netbeans 8.0上的更改计算器GUI程序在我第一次编写时运行,但在将文件从我的桌面复制到笔记本电脑后,“运行文件”按钮显示为灰色。关于如何让它再次运行的任何想法?

以下是代码:

package changecalculator;


public class CoinChange extends javax.swing.JFrame {

//Variablezs

 int centsAmount, cents, nickels, dimes, quarters;



 //Checking for button clicks


    public CoinChange() {
        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() {

        jButton0 = new javax.swing.JButton();
        clear = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        calculateChange = new javax.swing.JButton();
        display = new javax.swing.JFormattedTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        display2 = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(255, 255, 51));

        jButton0.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton0.setText("0");
        jButton0.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton0.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton0ActionPerformed(evt);
            }
        });

        clear.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        clear.setText("CLEAR");
        clear.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        clear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clearActionPerformed(evt);
            }
        });

        jButton7.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton7.setText("7");
        jButton7.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton8.setText("8");
        jButton8.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton9.setText("9");
        jButton9.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton4.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton4.setText("4");
        jButton4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton5.setText("5");
        jButton5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton6.setText("6");
        jButton6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton1.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton1.setText("1");
        jButton1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton2.setText("2");
        jButton2.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setFont(new java.awt.Font("Arial", 1, 36)); // NOI18N
        jButton3.setText("3");
        jButton3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        calculateChange.setFont(new java.awt.Font("Arial", 1, 24)); // NOI18N
        calculateChange.setText("Calculate Change");
        calculateChange.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        calculateChange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                calculateChangeActionPerformed(evt);
            }
        });

        display.setEditable(false);
        display.setAutoscrolls(false);
        display.setFont(new java.awt.Font("Cambria", 0, 16)); // NOI18N
        display.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                displayActionPerformed(evt);
            }
        });

        display2.setEditable(false);
        display2.setColumns(20);
        display2.setFont(new java.awt.Font("Arial", 0, 17)); // NOI18N
        display2.setRows(5);
        display2.setText("Please enter an amount of \nmoney in cents that is less than \n100:");
        jScrollPane1.setViewportView(display2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(calculateChange, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(display)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(29, 29, 29)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(0, 8, Short.MAX_VALUE)
                                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(33, 33, 33)
                                        .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(8, 8, 8)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 68, 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, 68, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addGap(105, 105, 105)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jButton0, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addGap(39, 39, 39))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(33, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(display, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(12, 12, 12)
                .addComponent(calculateChange, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton0, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

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

    private void clearActionPerformed(java.awt.event.ActionEvent evt) {                                      
   display.setText("");
    }                                     

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    display.setText(display.getText()+jButton1.getText());

    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton2.getText());

    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton3.getText());
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton4.getText());
    }                                        

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton5.getText());
    }                                        

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton6.getText());
    }                                        

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton7.getText());
    }                                        

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton8.getText());
    }                                        

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton9.getText());
    }                                        

    private void jButton0ActionPerformed(java.awt.event.ActionEvent evt) {                                         
     display.setText(display.getText()+jButton0.getText());
    }                                        

    private void calculateChangeActionPerformed(java.awt.event.ActionEvent evt) {                                                
    centsAmount = (Integer.parseInt(String.valueOf(display.getText())));

  quarters = centsAmount/25;
  dimes = (centsAmount-quarters*25)/10;
  nickels = ((centsAmount%25)%10)/5;
  cents = (centsAmount%10)%5;

  while (centsAmount >= 100 || centsAmount < 1){
    //display2.setText("");
    display2.setText("Please enter an amount in cents that is less than 100 and is greater than 0:");
//Making sure that the amount entered is less than 100 and greater than 0.
    centsAmount = (Integer.parseInt(String.valueOf(display.getText())));
//Asking the user to try again.
  quarters = centsAmount/25;
  dimes = (centsAmount-quarters*25)/10;
  nickels = ((centsAmount%25)%10)/5;
  cents = (centsAmount%10)%5;
//Recalculating
  }


display2.setText(centsAmount + " cents: ");
//First printing out the amount entered

//QUARTERS
    if (quarters > 1 && (dimes != 0 || nickels != 0 || cents != 0)){
    display2.setText(quarters + " quarters, ");
//Printing out "quarters," if the number of quarters is greater than 1 and it's not the last coin to be displayed.
}
    else if (quarters > 1 && dimes == 0 && nickels == 0 && cents == 0){
    display2.setText(quarters + " quarters.");
//Printing out "quarters." if the number of quarters is greater than 1 and it's the only coin to be displayed.
    }

    else if (quarters == 1 && (dimes != 0 || nickels != 0 || cents != 0)){
    display2.setText(quarters + " quarter, ");
//Printing out "quarter," if there is only 1 quarter and it's not the last coin to be displayed.
   }
    else if (quarters == 1 && dimes == 0 && nickels == 0 && cents == 0){
      display2.setText(quarters + " quarter.");
//Printing out "quarter." if there is only 1 quarter and it's the only coin to be displayed.
   }

//THIS REPEATS FOR THE REST OF THE COINS  

//DIMES
if (dimes > 1 && (nickels != 0 || cents != 0)){
    display2.setText(dimes + " dimes,");
  }
  else if (dimes > 1 && nickels == 0 && cents == 0 && quarters!=0){
      display2.setText(" and " + dimes + " dimes.");
    }
  else if (dimes > 1 && quarters == 0){
    display2.setText(dimes + " dimes.");
//Printing out "dimes." if the number of dimes is greater than 1 and it's the only coin displayed.
  }    
  else if (dimes == 1 && (nickels != 0 || cents != 0)){
      display2.setText(dimes + " dime,");
  }
  else if (dimes == 1 && nickels == 0 && cents == 0 && quarters!=0){
      display2.setText(" and " + dimes + " dime.");
  }
  else if (dimes == 1 && quarters == 0){
    display2.setText(dimes + " dime.");
//Printing out "dime." if there is 1 dime and it's the only coin displayed.
  }

//NICKELS
if (nickels > 1 && cents !=0){
    display2.setText(nickels + " nickels,");
  }
  else if (nickels > 1 && cents == 0){
      display2.setText("and " + nickels + " nickels.");
   }

   else if (nickels == 1 && cents !=0){

      display2.setText(nickels + " nickel,");
  }
   else if (nickels == 1 && (quarters !=0 || dimes!=0 ) && cents == 0){
      display2.setText("and " + nickels + " nickel.");
  }
   else if (nickels == 1 && quarters == 0 && dimes == 0){
     display2.setText(nickels + " nickel.");
//Printing "nickel." when it's the only coin to be displayed. There can only be 1 nickel, as 2 nickels make a dime.
   }

//CENTS    
if (cents > 1 && (quarters != 0 || dimes != 0 || nickels != 0)){
    display2.setText(" and " + cents + " cents. ");
  }
   else if (cents == 1 && (quarters != 0 || dimes != 0 || nickels != 0)){
      display2.setText(" and " + cents + " cent. ");
  }
   else if (cents >1 && quarters == 0 && dimes == 0 && nickels == 0){
     display2.setText(cents + " cents.");
   }
   else if (cents == 1 && quarters == 0 && dimes == 0 && nickels == 0){
    display2.setText(cents + " cent.");

}
    }                                               

    private void displayActionPerformed(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(CoinChange.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CoinChange.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CoinChange.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CoinChange.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 CoinChange().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify                     
    private javax.swing.JButton calculateChange;
    private javax.swing.JButton clear;
    private javax.swing.JFormattedTextField display;
    private javax.swing.JTextArea display2;
    private javax.swing.JButton jButton0;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration                   
}

1 个答案:

答案 0 :(得分:0)

复制文件还不够,您需要复制项目 。项目(nbproject目录所在的目录)包含运行它所需的信息。