Advertisement
casparcedro

C-Full

Mar 20th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.45 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package GUI;
  6.  
  7. /**
  8.  *
  9.  * @author Caspar Cedro
  10.  */
  11. public class CalculatorGUI extends javax.swing.JFrame {
  12.  
  13.     public double firstDouble; // the first value is stored here
  14.     public double secondDouble; // the second value is stored here
  15.     public double answer = 0; // self-explanatory, spiteful comment
  16.     boolean operatorIsSelected = false; // used to know if a value is firstDouble or secondDouble
  17.     String operators = ""; // used to denote operator to be used in calculation
  18.     String repeat = "";
  19.     int i = 0;
  20.  
  21.     /**
  22.      * Creates new form CalculatorGUI
  23.      */
  24.     public CalculatorGUI() {
  25.         initComponents();
  26.         result.setText(""); // ensures calculator screen is clear
  27.  
  28.     }
  29.    
  30.     /* The following code allows values to be set on the calculator screen and
  31.      manipulated. */
  32.     private void operation(String value){
  33.         String text = result.getText();
  34.         if (text.length() > 0 && operatorIsSelected == false) {
  35.             result.setText(result.getText() + value);
  36.         } else if (operatorIsSelected == true) {
  37.             //for (int i = 0; i < 1;i++) {
  38.                 result.setText(null);
  39.                 operatorIsSelected = false;
  40.                 result.setText(result.getText() + value);
  41.             //}
  42.         } else {
  43.             result.setText(value);
  44.         }
  45.     }
  46.  
  47.     /**
  48.      * This method is called from within the constructor to initialize the form.
  49.      * WARNING: Do NOT modify this code. The content of this method is always
  50.      * regenerated by the Form Editor.
  51.      */
  52.     @SuppressWarnings("unchecked")
  53.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  54.     private void initComponents() {
  55.  
  56.         division = new javax.swing.JButton();
  57.         one = new javax.swing.JButton();
  58.         four = new javax.swing.JButton();
  59.         seven = new javax.swing.JButton();
  60.         multiplication = new javax.swing.JButton();
  61.         two = new javax.swing.JButton();
  62.         five = new javax.swing.JButton();
  63.         eight = new javax.swing.JButton();
  64.         addition = new javax.swing.JButton();
  65.         three = new javax.swing.JButton();
  66.         six = new javax.swing.JButton();
  67.         nine = new javax.swing.JButton();
  68.         subtraction = new javax.swing.JButton();
  69.         zero = new javax.swing.JButton();
  70.         equals = new javax.swing.JButton();
  71.         decimal = new javax.swing.JButton();
  72.         clear = new javax.swing.JButton();
  73.         clearAll = new javax.swing.JButton();
  74.         result = new javax.swing.JFormattedTextField();
  75.  
  76.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  77.  
  78.         division.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  79.         division.setText("รท");
  80.         division.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  81.         division.addActionListener(new java.awt.event.ActionListener() {
  82.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  83.                 divisionActionPerformed(evt);
  84.             }
  85.         });
  86.  
  87.         one.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  88.         one.setText("1");
  89.         one.addActionListener(new java.awt.event.ActionListener() {
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  91.                 oneActionPerformed(evt);
  92.             }
  93.         });
  94.  
  95.         four.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  96.         four.setText("4");
  97.         four.addActionListener(new java.awt.event.ActionListener() {
  98.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  99.                 fourActionPerformed(evt);
  100.             }
  101.         });
  102.  
  103.         seven.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  104.         seven.setText("7");
  105.         seven.setToolTipText("");
  106.         seven.addActionListener(new java.awt.event.ActionListener() {
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  108.                 sevenActionPerformed(evt);
  109.             }
  110.         });
  111.  
  112.         multiplication.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  113.         multiplication.setText("x");
  114.         multiplication.addActionListener(new java.awt.event.ActionListener() {
  115.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  116.                 multiplicationActionPerformed(evt);
  117.             }
  118.         });
  119.  
  120.         two.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  121.         two.setText("2");
  122.         two.addActionListener(new java.awt.event.ActionListener() {
  123.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  124.                 twoActionPerformed(evt);
  125.             }
  126.         });
  127.  
  128.         five.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  129.         five.setText("5");
  130.         five.addActionListener(new java.awt.event.ActionListener() {
  131.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  132.                 fiveActionPerformed(evt);
  133.             }
  134.         });
  135.  
  136.         eight.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  137.         eight.setText("8");
  138.         eight.addActionListener(new java.awt.event.ActionListener() {
  139.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  140.                 eightActionPerformed(evt);
  141.             }
  142.         });
  143.  
  144.         addition.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  145.         addition.setText("+");
  146.         addition.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  147.         addition.addActionListener(new java.awt.event.ActionListener() {
  148.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  149.                 additionActionPerformed(evt);
  150.             }
  151.         });
  152.  
  153.         three.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  154.         three.setText("3");
  155.         three.addActionListener(new java.awt.event.ActionListener() {
  156.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  157.                 threeActionPerformed(evt);
  158.             }
  159.         });
  160.  
  161.         six.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  162.         six.setText("6");
  163.         six.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  164.         six.addActionListener(new java.awt.event.ActionListener() {
  165.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  166.                 sixActionPerformed(evt);
  167.             }
  168.         });
  169.  
  170.         nine.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  171.         nine.setText("9");
  172.         nine.addActionListener(new java.awt.event.ActionListener() {
  173.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  174.                 nineActionPerformed(evt);
  175.             }
  176.         });
  177.  
  178.         subtraction.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
  179.         subtraction.setText("-");
  180.         subtraction.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
  181.         subtraction.addActionListener(new java.awt.event.ActionListener() {
  182.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  183.                 subtractionActionPerformed(evt);
  184.             }
  185.         });
  186.  
  187.         zero.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  188.         zero.setText("0");
  189.         zero.addActionListener(new java.awt.event.ActionListener() {
  190.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  191.                 zeroActionPerformed(evt);
  192.             }
  193.         });
  194.  
  195.         equals.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  196.         equals.setText("=");
  197.         equals.addActionListener(new java.awt.event.ActionListener() {
  198.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  199.                 equalsActionPerformed(evt);
  200.             }
  201.         });
  202.  
  203.         decimal.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  204.         decimal.setText(".");
  205.  
  206.         clear.setText("C");
  207.  
  208.         clearAll.setText("CA");
  209.         clearAll.addActionListener(new java.awt.event.ActionListener() {
  210.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  211.                 clearAllActionPerformed(evt);
  212.             }
  213.         });
  214.  
  215.         result.setEditable(false);
  216.         result.addActionListener(new java.awt.event.ActionListener() {
  217.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  218.                 resultActionPerformed(evt);
  219.             }
  220.         });
  221.  
  222.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  223.         getContentPane().setLayout(layout);
  224.         layout.setHorizontalGroup(
  225.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  226.             .addGroup(layout.createSequentialGroup()
  227.                 .addContainerGap()
  228.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  229.                     .addComponent(result)
  230.                     .addGroup(layout.createSequentialGroup()
  231.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  232.                             .addGroup(layout.createSequentialGroup()
  233.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  234.                                     .addComponent(one, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  235.                                     .addComponent(four, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  236.                                     .addComponent(seven, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  237.                                     .addComponent(division))
  238.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  239.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  240.                                     .addComponent(two, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  241.                                     .addComponent(five, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  242.                                     .addComponent(eight, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  243.                                     .addComponent(multiplication, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  244.                                     .addComponent(zero)))
  245.                             .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
  246.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  247.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  248.                             .addGroup(layout.createSequentialGroup()
  249.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  250.                                     .addComponent(three, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  251.                                     .addComponent(decimal, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  252.                                     .addComponent(six, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  253.                                     .addComponent(addition, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  254.                                     .addComponent(nine, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  255.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  256.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  257.                                     .addComponent(subtraction, javax.swing.GroupLayout.DEFAULT_SIZE, 82, Short.MAX_VALUE)
  258.                                     .addComponent(equals, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  259.                             .addComponent(clearAll, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
  260.                         .addGap(0, 0, Short.MAX_VALUE)))
  261.                 .addContainerGap())
  262.         );
  263.         layout.setVerticalGroup(
  264.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  265.             .addGroup(layout.createSequentialGroup()
  266.                 .addContainerGap()
  267.                 .addComponent(result, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
  268.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  269.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  270.                     .addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  271.                     .addComponent(clearAll, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  272.                 .addGap(8, 8, 8)
  273.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  274.                     .addGroup(layout.createSequentialGroup()
  275.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  276.                             .addGroup(layout.createSequentialGroup()
  277.                                 .addComponent(division, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  278.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  279.                                 .addComponent(one, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  280.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  281.                                 .addComponent(four, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  282.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  283.                                 .addComponent(seven, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
  284.                             .addGroup(layout.createSequentialGroup()
  285.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  286.                                     .addComponent(addition, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  287.                                     .addComponent(subtraction, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE))
  288.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  289.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  290.                                     .addComponent(equals, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
  291.                                     .addGroup(layout.createSequentialGroup()
  292.                                         .addComponent(three, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  293.                                         .addGap(57, 57, 57)
  294.                                         .addComponent(nine, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))))
  295.                             .addGroup(layout.createSequentialGroup()
  296.                                 .addGap(102, 102, 102)
  297.                                 .addComponent(six, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
  298.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  299.                         .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
  300.                     .addGroup(layout.createSequentialGroup()
  301.                         .addComponent(multiplication, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  302.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  303.                         .addComponent(two, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  304.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  305.                         .addComponent(five, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  306.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  307.                         .addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
  308.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  309.                         .addComponent(zero, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)))
  310.                 .addContainerGap(12, Short.MAX_VALUE))
  311.         );
  312.  
  313.         pack();
  314.     }// </editor-fold>                        
  315.  
  316.     private void oneActionPerformed(java.awt.event.ActionEvent evt) {                                    
  317.  
  318. operation("1");
  319.     }                                  
  320.  
  321.     private void twoActionPerformed(java.awt.event.ActionEvent evt) {                                    
  322.  
  323. operation("2");
  324.     }                                  
  325.  
  326.     private void threeActionPerformed(java.awt.event.ActionEvent evt) {                                      
  327.  
  328. operation("3");
  329.     }                                    
  330.  
  331.     private void fourActionPerformed(java.awt.event.ActionEvent evt) {                                    
  332.  
  333. operation("4");
  334.     }                                    
  335.  
  336.     private void fiveActionPerformed(java.awt.event.ActionEvent evt) {                                    
  337.  
  338. operation("5");
  339.     }                                    
  340.  
  341.     private void sixActionPerformed(java.awt.event.ActionEvent evt) {                                    
  342.  
  343. operation("6");
  344.     }                                  
  345.  
  346.     private void sevenActionPerformed(java.awt.event.ActionEvent evt) {                                      
  347.  
  348. operation("7");
  349.     }                                    
  350.  
  351.     private void eightActionPerformed(java.awt.event.ActionEvent evt) {                                      
  352.  
  353. operation("8");
  354.     }                                    
  355.  
  356.     private void nineActionPerformed(java.awt.event.ActionEvent evt) {                                    
  357.  
  358. operation("9");
  359.     }                                    
  360.  
  361.     private void zeroActionPerformed(java.awt.event.ActionEvent evt) {                                    
  362.  
  363. operation("0");
  364.     }                                    
  365.  
  366.     private void clearAllActionPerformed(java.awt.event.ActionEvent evt) {                                        
  367.  
  368.         result.setText("");
  369.         firstDouble = 0;
  370.         secondDouble = 0;
  371.         i = 0;
  372.     }                                        
  373.  
  374.     private void resultActionPerformed(java.awt.event.ActionEvent evt) {                                      
  375. // This is the calculator screen, do not edit as all the other buttons manipulate this.
  376.     }                                      
  377.  
  378.     private void divisionActionPerformed(java.awt.event.ActionEvent evt) {                                        
  379.  
  380.         String numberwords = result.getText();
  381.         firstDouble = Double.parseDouble(numberwords);
  382.         result.setText("/");
  383.         operatorIsSelected = true;
  384.         operators = "/";
  385.         repeat = "/";
  386.     }                                        
  387.  
  388.     private void multiplicationActionPerformed(java.awt.event.ActionEvent evt) {                                              
  389.  
  390.         String numberwords = result.getText();
  391.         firstDouble = Double.parseDouble(numberwords);
  392.         result.setText("X");
  393.         operatorIsSelected = true;
  394.         operators = "*";
  395.         repeat = "*";
  396.     }                                              
  397.  
  398.     private void additionActionPerformed(java.awt.event.ActionEvent evt) {                                        
  399.  
  400.         String numberwords = result.getText();
  401.         firstDouble = Double.parseDouble(numberwords);
  402.         result.setText("+");
  403.         operatorIsSelected = true;
  404.         operators = "+";
  405.         repeat = "+";
  406.     }                                        
  407.  
  408.     private void subtractionActionPerformed(java.awt.event.ActionEvent evt) {                                            
  409.  
  410.         String numberwords = result.getText();
  411.         firstDouble = Double.parseDouble(numberwords);
  412.         result.setText("-");
  413.         operatorIsSelected = true;
  414.         operators = "-";
  415.         repeat = "-";
  416.     }                                          
  417.  
  418.     private void equalsActionPerformed(java.awt.event.ActionEvent evt) {                                      
  419.  
  420.         secondDouble = Double.parseDouble(result.getText());
  421.  
  422.         switch (operators) {
  423.             case "/":
  424.                 answer = firstDouble / secondDouble;
  425.                 operators = "";
  426.                 break;
  427.             case "*":
  428.                 answer = firstDouble * secondDouble;
  429.                 operators = "";
  430.                 break;
  431.             case "+":
  432.                 answer = firstDouble + secondDouble;
  433.                 operators = "";
  434.                 break;
  435.             case "-":
  436.                 answer = firstDouble - secondDouble;
  437.                 operators = "";
  438.                 break;
  439.             default:
  440.                 if(i == 0){
  441.        double savedValue = secondDouble;
  442.                 switch(repeat){  
  443.             case "/":
  444.                 answer = answer / savedValue;
  445.                 operators = "";
  446.                 break;
  447.             case "*":
  448.                 answer = answer * savedValue;
  449.                 operators = "";
  450.                 break;
  451.             case "+":
  452.                 answer = answer + savedValue;
  453.                 operators = "";
  454.                 break;
  455.             case "-":
  456.                 answer = answer - savedValue;
  457.                 operators = "";
  458.                 break;
  459.                 }
  460.                 };
  461.         }
  462.  
  463.         result.setText("" + answer + "");
  464.  
  465.     }                                      
  466.  
  467.     /**
  468.      * @param args the command line arguments
  469.      */
  470.     public static void main(String args[]) {
  471.         /* Set the Nimbus look and feel */
  472.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  473.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  474.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  475.          */
  476.         try {
  477.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  478.                 if ("Nimbus".equals(info.getName())) {
  479.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  480.                     break;
  481.  
  482.  
  483.  
  484.  
  485.                 }
  486.             }
  487.         } catch (ClassNotFoundException ex) {
  488.             java.util.logging.Logger.getLogger(CalculatorGUI.class
  489.                     .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  490.         } catch (InstantiationException ex) {
  491.             java.util.logging.Logger.getLogger(CalculatorGUI.class
  492.                     .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  493.         } catch (IllegalAccessException ex) {
  494.             java.util.logging.Logger.getLogger(CalculatorGUI.class
  495.                     .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  496.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  497.             java.util.logging.Logger.getLogger(CalculatorGUI.class
  498.                     .getName()).log(java.util.logging.Level.SEVERE, null, ex);
  499.         }
  500.         //</editor-fold>
  501.  
  502.         /* Create and display the form */
  503.         java.awt.EventQueue.invokeLater(new Runnable() {
  504.             public void run() {
  505.                 new CalculatorGUI().setVisible(true);
  506.             }
  507.         });
  508.     }
  509.     // Variables declaration - do not modify                    
  510.     private javax.swing.JButton addition;
  511.     private javax.swing.JButton clear;
  512.     private javax.swing.JButton clearAll;
  513.     private javax.swing.JButton decimal;
  514.     private javax.swing.JButton division;
  515.     private javax.swing.JButton eight;
  516.     private javax.swing.JButton equals;
  517.     private javax.swing.JButton five;
  518.     private javax.swing.JButton four;
  519.     private javax.swing.JButton multiplication;
  520.     private javax.swing.JButton nine;
  521.     private javax.swing.JButton one;
  522.     private javax.swing.JFormattedTextField result;
  523.     private javax.swing.JButton seven;
  524.     private javax.swing.JButton six;
  525.     private javax.swing.JButton subtraction;
  526.     private javax.swing.JButton three;
  527.     private javax.swing.JButton two;
  528.     private javax.swing.JButton zero;
  529.     // End of variables declaration                  
  530. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement