Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.37 KB | None | 0 0
  1. package calc;
  2.  
  3. import javax.swing.*;
  4.  
  5. public class Calc {
  6.     public static void main(String[] args) {
  7.         try {
  8.             String systemLookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
  9.             UIManager.setLookAndFeel(systemLookAndFeelClassName);
  10.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
  11.         }
  12.          java.awt.EventQueue.invokeLater(() -> {
  13.              Gui gui = new Gui();
  14.              gui.setLocationRelativeTo(null);
  15.              gui.setVisible(true);
  16.         });      
  17.     }    
  18. }
  19.  
  20. package calc;
  21.  
  22. import java.awt.event.*;
  23. import java.awt.*;
  24.  
  25. public class Gui extends javax.swing.JFrame {
  26.     int firstNum = 0;
  27.     String operation = "";
  28.  
  29.     public Gui() {
  30.         initComponents();
  31.     }
  32.  
  33.     @SuppressWarnings("unchecked")
  34.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  35.     private void initComponents() {
  36.  
  37.         jTextField1 = new javax.swing.JTextField();
  38.         jButton1 = new javax.swing.JButton();
  39.         jButton5 = new javax.swing.JButton();
  40.         jButton6 = new javax.swing.JButton();
  41.         jButton7 = new javax.swing.JButton();
  42.         jButton8 = new javax.swing.JButton();
  43.         jButton9 = new javax.swing.JButton();
  44.         jButton10 = new javax.swing.JButton();
  45.         jButton11 = new javax.swing.JButton();
  46.         jButton12 = new javax.swing.JButton();
  47.         jButton13 = new javax.swing.JButton();
  48.         jButton14 = new javax.swing.JButton();
  49.         jButton15 = new javax.swing.JButton();
  50.         jButton16 = new javax.swing.JButton();
  51.         jButton17 = new javax.swing.JButton();
  52.         jButton18 = new javax.swing.JButton();
  53.         jButton19 = new javax.swing.JButton();
  54.  
  55.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  56.         setTitle("Calculator v0.1");
  57.         setBackground(new java.awt.Color(204, 204, 204));
  58.         setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  59.         setForeground(new java.awt.Color(255, 255, 255));
  60.         setResizable(false);
  61.  
  62.         jTextField1.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
  63.         jTextField1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
  64.         jTextField1.setToolTipText("");
  65.         jTextField1.setEnabled(false);
  66.         jTextField1.addMouseListener(new java.awt.event.MouseAdapter() {
  67.             public void mouseClicked(java.awt.event.MouseEvent evt) {
  68.                 jTextField1MouseClicked(evt);
  69.             }
  70.         });
  71.  
  72.         jButton1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  73.         jButton1.setText("7");
  74.         jButton1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  75.         jButton1.setFocusPainted(false);
  76.         jButton1.setFocusable(false);
  77.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  78.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  79.                 jButton1ActionPerformed(evt);
  80.             }
  81.         });
  82.  
  83.         jButton5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  84.         jButton5.setText("4");
  85.         jButton5.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  86.         jButton5.setFocusPainted(false);
  87.         jButton5.setFocusable(false);
  88.         jButton5.addActionListener(new java.awt.event.ActionListener() {
  89.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  90.                 jButton5ActionPerformed(evt);
  91.             }
  92.         });
  93.  
  94.         jButton6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  95.         jButton6.setText("1");
  96.         jButton6.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  97.         jButton6.setFocusPainted(false);
  98.         jButton6.setFocusable(false);
  99.         jButton6.addActionListener(new java.awt.event.ActionListener() {
  100.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  101.                 jButton6ActionPerformed(evt);
  102.             }
  103.         });
  104.  
  105.         jButton7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  106.         jButton7.setText("2");
  107.         jButton7.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  108.         jButton7.setFocusPainted(false);
  109.         jButton7.setFocusable(false);
  110.         jButton7.addActionListener(new java.awt.event.ActionListener() {
  111.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  112.                 jButton7ActionPerformed(evt);
  113.             }
  114.         });
  115.  
  116.         jButton8.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  117.         jButton8.setText("8");
  118.         jButton8.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  119.         jButton8.setFocusPainted(false);
  120.         jButton8.setFocusable(false);
  121.         jButton8.addActionListener(new java.awt.event.ActionListener() {
  122.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  123.                 jButton8ActionPerformed(evt);
  124.             }
  125.         });
  126.  
  127.         jButton9.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  128.         jButton9.setText("9");
  129.         jButton9.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  130.         jButton9.setFocusPainted(false);
  131.         jButton9.setFocusable(false);
  132.         jButton9.addActionListener(new java.awt.event.ActionListener() {
  133.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  134.                 jButton9ActionPerformed(evt);
  135.             }
  136.         });
  137.  
  138.         jButton10.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  139.         jButton10.setText("/");
  140.         jButton10.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  141.         jButton10.setFocusPainted(false);
  142.         jButton10.setFocusable(false);
  143.         jButton10.addActionListener(new java.awt.event.ActionListener() {
  144.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  145.                 jButton10ActionPerformed(evt);
  146.             }
  147.         });
  148.  
  149.         jButton11.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  150.         jButton11.setText("5");
  151.         jButton11.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  152.         jButton11.setFocusPainted(false);
  153.         jButton11.setFocusable(false);
  154.         jButton11.addActionListener(new java.awt.event.ActionListener() {
  155.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  156.                 jButton11ActionPerformed(evt);
  157.             }
  158.         });
  159.  
  160.         jButton12.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  161.         jButton12.setText("6");
  162.         jButton12.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  163.         jButton12.setFocusPainted(false);
  164.         jButton12.setFocusable(false);
  165.         jButton12.addActionListener(new java.awt.event.ActionListener() {
  166.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  167.                 jButton12ActionPerformed(evt);
  168.             }
  169.         });
  170.  
  171.         jButton13.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  172.         jButton13.setText("*");
  173.         jButton13.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  174.         jButton13.setFocusPainted(false);
  175.         jButton13.setFocusable(false);
  176.         jButton13.addActionListener(new java.awt.event.ActionListener() {
  177.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  178.                 jButton13ActionPerformed(evt);
  179.             }
  180.         });
  181.  
  182.         jButton14.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  183.         jButton14.setText("3");
  184.         jButton14.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  185.         jButton14.setFocusPainted(false);
  186.         jButton14.setFocusable(false);
  187.         jButton14.addActionListener(new java.awt.event.ActionListener() {
  188.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  189.                 jButton14ActionPerformed(evt);
  190.             }
  191.         });
  192.  
  193.         jButton15.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  194.         jButton15.setText("+");
  195.         jButton15.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  196.         jButton15.setFocusPainted(false);
  197.         jButton15.setFocusable(false);
  198.         jButton15.addActionListener(new java.awt.event.ActionListener() {
  199.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  200.                 jButton15ActionPerformed(evt);
  201.             }
  202.         });
  203.  
  204.         jButton16.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  205.         jButton16.setText("0");
  206.         jButton16.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  207.         jButton16.setFocusPainted(false);
  208.         jButton16.setFocusable(false);
  209.         jButton16.addActionListener(new java.awt.event.ActionListener() {
  210.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  211.                 jButton16ActionPerformed(evt);
  212.             }
  213.         });
  214.  
  215.         jButton17.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  216.         jButton17.setText(".");
  217.         jButton17.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  218.         jButton17.setFocusPainted(false);
  219.         jButton17.setFocusable(false);
  220.  
  221.         jButton18.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  222.         jButton18.setText("=");
  223.         jButton18.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  224.         jButton18.setFocusPainted(false);
  225.         jButton18.setFocusable(false);
  226.         jButton18.addActionListener(new java.awt.event.ActionListener() {
  227.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  228.                 jButton18ActionPerformed(evt);
  229.             }
  230.         });
  231.  
  232.         jButton19.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  233.         jButton19.setText("-");
  234.         jButton19.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
  235.         jButton19.setFocusPainted(false);
  236.         jButton19.setFocusable(false);
  237.         jButton19.addActionListener(new java.awt.event.ActionListener() {
  238.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  239.                 jButton19ActionPerformed(evt);
  240.             }
  241.         });
  242.  
  243.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  244.         getContentPane().setLayout(layout);
  245.         layout.setHorizontalGroup(
  246.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  247.             .addGroup(layout.createSequentialGroup()
  248.                 .addContainerGap()
  249.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  250.                     .addComponent(jTextField1)
  251.                     .addGroup(layout.createSequentialGroup()
  252.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  253.                             .addGroup(layout.createSequentialGroup()
  254.                                 .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  255.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  256.                                 .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  257.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  258.                                 .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  259.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  260.                                 .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
  261.                             .addGroup(layout.createSequentialGroup()
  262.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  263.                                     .addGroup(layout.createSequentialGroup()
  264.                                         .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  265.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  266.                                         .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
  267.                                     .addGroup(layout.createSequentialGroup()
  268.                                         .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  269.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  270.                                         .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
  271.                                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  272.                                     .addGroup(layout.createSequentialGroup()
  273.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  274.                                         .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  275.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  276.                                         .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
  277.                                     .addGroup(layout.createSequentialGroup()
  278.                                         .addGap(6, 6, 6)
  279.                                         .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  280.                                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  281.                                         .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))))
  282.                             .addGroup(layout.createSequentialGroup()
  283.                                 .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  284.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  285.                                 .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  286.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  287.                                 .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
  288.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  289.                                 .addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)))
  290.                         .addGap(0, 0, Short.MAX_VALUE)))
  291.                 .addContainerGap())
  292.         );
  293.         layout.setVerticalGroup(
  294.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  295.             .addGroup(layout.createSequentialGroup()
  296.                 .addContainerGap()
  297.                 .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  298.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  299.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  300.                     .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  301.                     .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  302.                     .addComponent(jButton9, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  303.                     .addComponent(jButton10, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  304.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  305.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  306.                     .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  307.                     .addComponent(jButton12, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  308.                     .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  309.                     .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  310.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  311.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  312.                     .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  313.                     .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  314.                     .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  315.                     .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  316.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  317.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  318.                     .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  319.                     .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  320.                     .addComponent(jButton18, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
  321.                     .addComponent(jButton19, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
  322.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  323.         );
  324.  
  325.         pack();
  326.     }// </editor-fold>//GEN-END:initComponents
  327.  
  328.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  329.         jTextField1.setText(jTextField1.getText() + "7");
  330.     }//GEN-LAST:event_jButton1ActionPerformed
  331.  
  332.     private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
  333.         jTextField1.setText(jTextField1.getText() + "8");
  334.     }//GEN-LAST:event_jButton8ActionPerformed
  335.  
  336.     private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
  337.         jTextField1.setText(jTextField1.getText() + "9");
  338.     }//GEN-LAST:event_jButton9ActionPerformed
  339.  
  340.     private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
  341.         jTextField1.setText(jTextField1.getText() + "0");
  342.     }//GEN-LAST:event_jButton16ActionPerformed
  343.  
  344.     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
  345.         jTextField1.setText(jTextField1.getText() + "1");
  346.     }//GEN-LAST:event_jButton6ActionPerformed
  347.  
  348.     private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
  349.        
  350.         jTextField1.setText(jTextField1.getText() + "2");
  351.     }//GEN-LAST:event_jButton7ActionPerformed
  352.  
  353.     private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
  354.         jTextField1.setText(jTextField1.getText() + "3");
  355.     }//GEN-LAST:event_jButton14ActionPerformed
  356.  
  357.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
  358.         jTextField1.setText(jTextField1.getText() + "4");
  359.     }//GEN-LAST:event_jButton5ActionPerformed
  360.  
  361.     private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
  362.         jTextField1.setText(jTextField1.getText() + "5");
  363.     }//GEN-LAST:event_jButton11ActionPerformed
  364.  
  365.     private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
  366.         jTextField1.setText(jTextField1.getText() + "6");
  367.     }//GEN-LAST:event_jButton12ActionPerformed
  368.  
  369.     private void jTextField1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1MouseClicked
  370.         String temp = jTextField1.getText();
  371.         int len = 0;
  372.         if(len != temp.length()) {
  373.             jTextField1.setText(temp.substring(0, temp.length() - 1).trim());  
  374.         }
  375.     }//GEN-LAST:event_jTextField1MouseClicked
  376.  
  377.     private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
  378.         firstNum = Integer.valueOf(jTextField1.getText());
  379.         operation = " / ";
  380.         jTextField1.setText(firstNum + operation);
  381.     }//GEN-LAST:event_jButton10ActionPerformed
  382.  
  383.     private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
  384.         firstNum = Integer.valueOf(jTextField1.getText());
  385.         operation = " * ";
  386.         jTextField1.setText(firstNum + operation);
  387.     }//GEN-LAST:event_jButton13ActionPerformed
  388.  
  389.     private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
  390.         firstNum = Integer.valueOf(jTextField1.getText());
  391.         operation = " + ";
  392.         jTextField1.setText(firstNum + operation);
  393.     }//GEN-LAST:event_jButton15ActionPerformed
  394.  
  395.     private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton19ActionPerformed
  396.         firstNum = Integer.valueOf(jTextField1.getText());
  397.         operation = " - ";
  398.         jTextField1.setText(firstNum + operation);
  399.     }//GEN-LAST:event_jButton19ActionPerformed
  400.  
  401.     private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed
  402.         String temp = jTextField1.getText();
  403.         int a = temp.indexOf("*");
  404.         int b = temp.indexOf("/");
  405.         int c = temp.indexOf("-");
  406.         int d = temp.indexOf("+");
  407.         int secondNum;
  408.         if(operation.trim().equals("*")) {
  409.            secondNum = Integer.valueOf(temp.substring(a + 2));
  410.            int p1 = firstNum * secondNum;
  411.            jTextField1.setText(String.valueOf(p1));
  412.         } else if (operation.trim().equals("/")) {
  413.            secondNum = Integer.valueOf(temp.substring(b + 2));
  414.            int p2 = firstNum / secondNum;
  415.            jTextField1.setText(String.valueOf(p2));
  416.         } else if (operation.trim().equals("-")) {
  417.            secondNum = Integer.valueOf(temp.substring(c + 2));
  418.            int p3 = firstNum - secondNum;
  419.            jTextField1.setText(String.valueOf(p3));
  420.         } else if (operation.trim().equals("+")) {
  421.            secondNum = Integer.valueOf(temp.substring(d + 2));
  422.            int p4 = firstNum + secondNum;
  423.            jTextField1.setText(String.valueOf(p4));
  424.         }
  425.         //temp = (temp.substring(a, a+1));
  426.         //jTextField1.setText(temp);
  427.      
  428.        
  429.        
  430.        
  431.        
  432.        
  433.     }//GEN-LAST:event_jButton18ActionPerformed
  434.  
  435.    
  436.     // Variables declaration - do not modify//GEN-BEGIN:variables
  437.     private javax.swing.JButton jButton1;
  438.     private javax.swing.JButton jButton10;
  439.     private javax.swing.JButton jButton11;
  440.     private javax.swing.JButton jButton12;
  441.     private javax.swing.JButton jButton13;
  442.     private javax.swing.JButton jButton14;
  443.     private javax.swing.JButton jButton15;
  444.     private javax.swing.JButton jButton16;
  445.     private javax.swing.JButton jButton17;
  446.     private javax.swing.JButton jButton18;
  447.     private javax.swing.JButton jButton19;
  448.     private javax.swing.JButton jButton5;
  449.     private javax.swing.JButton jButton6;
  450.     private javax.swing.JButton jButton7;
  451.     private javax.swing.JButton jButton8;
  452.     private javax.swing.JButton jButton9;
  453.     private javax.swing.JTextField jTextField1;
  454.     // End of variables declaration//GEN-END:variables
  455. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement