Advertisement
Guest User

Calc project in NB, for stackOF

a guest
Jan 2nd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.81 KB | None | 0 0
  1.    
  2. package calcGui;
  3.  
  4.  
  5. public class GUI extends javax.swing.JFrame {
  6.    
  7.     double firstNumber;
  8.     double secondNumber;
  9.     String operation;  
  10.  
  11.     /** Creates new form GUI */
  12.     public GUI() {
  13.         initComponents();
  14.     }
  15.     @SuppressWarnings("unchecked")
  16.       "Generated Code spoiler thingy"                                      
  17.  
  18. private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  19.     String input = txtDisplay.getText() + btn1.getText();
  20.     txtDisplay.setText(input);
  21. }                                    
  22.  
  23. private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  24.     String input = txtDisplay.getText() + btn2.getText();
  25.     txtDisplay.setText(input);
  26. }                                    
  27.  
  28. private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  29.     String input = txtDisplay.getText() + btn3.getText();
  30.     txtDisplay.setText(input);
  31. }                                    
  32.  
  33. private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  34.     String input = txtDisplay.getText() + btn4.getText();
  35.     txtDisplay.setText(input);
  36. }                                    
  37.  
  38. private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  39.     String input = txtDisplay.getText() + btn5.getText();
  40.     txtDisplay.setText(input);
  41. }                                    
  42.  
  43. private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  44.     String input = txtDisplay.getText() + btn6.getText();
  45.     txtDisplay.setText(input);
  46. }                                    
  47.  
  48. private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  49.     String input = txtDisplay.getText() + btn7.getText();
  50.     txtDisplay.setText(input);
  51. }                                    
  52.  
  53. private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  54.     String input = txtDisplay.getText() + btn8.getText();
  55.     txtDisplay.setText(input);
  56. }                                    
  57.  
  58. private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  59.     String input = txtDisplay.getText() + btn9.getText();
  60.     txtDisplay.setText(input);
  61. }                                    
  62.  
  63. private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {                                    
  64.     String input = txtDisplay.getText() + btn0.getText();
  65.     txtDisplay.setText(input);
  66. }                                    
  67.  
  68. private void btnClrActionPerformed(java.awt.event.ActionEvent evt) {                                      
  69.     txtDisplay.setText("");
  70. }                                      
  71.  
  72. private void btnPtActionPerformed(java.awt.event.ActionEvent evt) {                                      
  73.     int count = txtDisplay.getText().length() - txtDisplay.getText().replace(".", "").length();
  74.    
  75.     if(count == 0){
  76.         String input= txtDisplay.getText() + btnPt.getText();
  77.         txtDisplay.setText(input);
  78.     }
  79.     else{
  80.        
  81.     }
  82. }                                    
  83.  
  84. private void btnPlusActionPerformed(java.awt.event.ActionEvent evt) {                                        
  85.  
  86.     firstNumber = Double.parseDouble(txtDisplay.getText());
  87.     txtDisplay.setText("");
  88.     operation = "+";
  89.    
  90.  
  91.  
  92. }                                      
  93.  
  94. private void btnMnsActionPerformed(java.awt.event.ActionEvent evt) {                                      
  95.     firstNumber = Double.parseDouble(txtDisplay.getText());
  96.     txtDisplay.setText("");
  97.     operation = "-";
  98. }                                      
  99.  
  100. private void btnMultiActionPerformed(java.awt.event.ActionEvent evt) {                                        
  101.     firstNumber = Double.parseDouble(txtDisplay.getText());
  102.     txtDisplay.setText("");
  103.     operation = "*";
  104. }                                        
  105.  
  106. private void btnDivActionPerformed(java.awt.event.ActionEvent evt) {                                      
  107.     firstNumber = Double.parseDouble(txtDisplay.getText());
  108.     txtDisplay.setText("");
  109.     operation = "/";
  110. }                                      
  111.  
  112. private void btnEqActionPerformed(java.awt.event.ActionEvent evt) {                                      
  113.     secondNumber = Double.parseDouble(txtDisplay.getText());
  114.     if ("+".equals(operation)) {
  115.         double result = firstNumber + secondNumber;
  116.             String answer = Double.toString(result);
  117.             txtDisplay.setText(answer);
  118.     }
  119.     else if ("-".equals(operation))  {
  120.         double result = firstNumber - secondNumber;
  121.             String answer = Double.toString(result);
  122.             txtDisplay.setText(answer);
  123.    
  124. }    
  125.        else if ("*".equals(operation))  {
  126.         double result = firstNumber * secondNumber;
  127.             String answer = Double.toString(result);
  128.             txtDisplay.setText(answer);
  129.    
  130. }  
  131.        else  {
  132.         double result = firstNumber / secondNumber;
  133.             String answer = Double.toString(result);
  134.             txtDisplay.setText(answer);
  135.    
  136. }    
  137. }                                    
  138.  
  139. private void btnSignActionPerformed(java.awt.event.ActionEvent evt) {                                        
  140.     String number = txtDisplay.getText();
  141.     double number1 = Double.parseDouble(number);
  142.     number1 = number1 * (-1);
  143.     txtDisplay.setText(String.valueOf(number1));
  144. }  
  145.  
  146.     /**
  147.      * @param args the command line arguments
  148.      */
  149.     public static void main(String args[]) {
  150.         /* Set the Nimbus look and feel */
  151.         /* Create and display the form */
  152.           "Look and feel spoiler thingy"
  153.         java.awt.EventQueue.invokeLater(new Runnable() {
  154.  
  155.             public void run() {
  156.                 new GUI().setVisible(true);
  157.             }
  158.         });
  159.     }
  160.     // Variables declaration - do not modify                    
  161.     private javax.swing.JButton btn0;
  162.     private javax.swing.JButton btn1;
  163.     private javax.swing.JButton btn2;
  164.     private javax.swing.JButton btn3;
  165.     private javax.swing.JButton btn4;
  166.     private javax.swing.JButton btn5;
  167.     private javax.swing.JButton btn6;
  168.     private javax.swing.JButton btn7;
  169.     private javax.swing.JButton btn8;
  170.     private javax.swing.JButton btn9;
  171.     private javax.swing.JButton btnClr;
  172.     private javax.swing.JButton btnDiv;
  173.     private javax.swing.JButton btnEq;
  174.     private javax.swing.JButton btnMns;
  175.     private javax.swing.JButton btnMulti;
  176.     private javax.swing.JButton btnPlus;
  177.     private javax.swing.JButton btnPt;
  178.     private javax.swing.JButton btnSign;
  179.     private javax.swing.JTextField txtDisplay;
  180.     // End of variables declaration                  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement