Advertisement
Guest User

PROJECT

a guest
Apr 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 45.75 KB | None | 0 0
  1. package sub;
  2.  
  3. import java.awt.Color;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.ResultSet;
  7. import java.sql.Statement;
  8. import java.util.*;
  9. import javax.swing.*;
  10.  
  11. /*
  12.  * To change this license header, choose License Headers in Project Properties.
  13.  * To change this template file, choose Tools | Templates
  14.  * and open the template in the editor.
  15.  */
  16. /**
  17.  *
  18.  * @author welcome
  19.  */
  20. public class advance extends javax.swing.JFrame {
  21.  
  22.     final static int GARBAGE = -123456;
  23.     static String memory = "";
  24.  
  25.     public static int factorial(int n) {
  26.         int i = 1, res = 1;
  27.         for (i = 1; i <= n; i++) {
  28.             res *= i;
  29.         }
  30.         return (res);
  31.     }
  32.  
  33.     public static int isOperator(char ch) {
  34.         if (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '^' || ch == 's' || ch == 'S' || ch == 't') {
  35.             return (1);
  36.         } else if (ch == 'c' || ch == 'C' || ch == 'l' || ch == 'L' || ch == '!' || ch == 'r' || ch == 'R' || ch == 'T') {
  37.             return (1);
  38.         } else if (ch == 'h' || ch == 'm' || ch == 'n' || ch == 'x') {
  39.             return (1);
  40.         } else {
  41.             return (0);
  42.         }
  43.     }
  44.  
  45.     public static int isAlpha(char ch) {
  46.         if (ch == 's' || ch == 'S') {
  47.             return (1);
  48.         } else if (ch == 'c' || ch == 'C') {
  49.             return (1);
  50.         } else if (ch == 't' || ch == 'T') {
  51.             return (1);
  52.         } else if (ch == 'l' || ch == 'L') {
  53.             return (1);
  54.         } else if (ch == 'r' || ch == 'R') {
  55.             return (1);
  56.         }
  57.         if (ch == 'h' || ch == 'm') {
  58.             return (1);
  59.         }
  60.         if (ch == 'n' || ch == '!') {
  61.             return (1);
  62.         }
  63.         if (ch == 'x') {
  64.             return (1);
  65.         } else {
  66.             return (0);
  67.         }
  68.     }
  69.      public static int hasPrecedence(char op) {
  70.         if (op == '(' || op == ')') {// || op2=='s' || op2=='c' || op2=='l' || op2=='L' || op2=='r')
  71.             System.out.println("5..");
  72.             return 5;
  73.         }
  74.         if (advance.isAlpha(op) == 1) {
  75.             System.out.println("4..");
  76.             return 4;
  77.         }
  78.         if ((op == '^' || op == '*' || op == '/')) {// && (op2 == '+' || op2 == '-')){
  79.             System.out.println("3..");
  80.             return 3;
  81.         } else if (op == '+' || op == '-') {
  82.             System.out.println("2..");
  83.             return 2;
  84.         }
  85.         return 0;
  86.     }
  87.      
  88.      public static double applyOp(char op, double b, double a) {
  89.         switch (op) {
  90.             case '+':
  91.                 return a + b;
  92.             case '-':
  93.                 return a - b;
  94.             case '*':
  95.                 return a * b;
  96.             case '/':
  97.                 if (b == 0) {
  98.                     throw new UnsupportedOperationException("WRONG INPUT AS DIVISOR");
  99.                 }
  100.                 return a / b;
  101.             case '^':
  102.                 return (Math.pow(a, b));
  103.             case 's':
  104.                 //if(advance.rb1.isSelected())
  105.                 return (Math.sin(Math.toRadians(b)));
  106.             case 'c':
  107.                 return (Math.cos(Math.toRadians(b)));
  108.             case 't':
  109.                 return (Math.tan(Math.toRadians(b)));
  110.             case 'r':
  111.                 return (Math.sqrt(b));
  112.             case 'R':
  113.                 return (Math.cbrt(b));
  114.             case 'l':
  115.                 return (Math.log10(b));
  116.             case 'L':
  117.                 return (Math.log(b));
  118.             case 'S':
  119.                 return (Math.asin(b));
  120.             case 'h':
  121.                 return (Math.sinh(b));
  122.             case 'm':
  123.                 return (Math.cosh(b));
  124.             case 'n':
  125.                 return (Math.tanh(b));
  126.             case '!':
  127.                 return ((double) advance.factorial((int) b));
  128.             case 'x':
  129.                 return (Math.exp(b));
  130.  
  131.         }
  132.         return 0;
  133.     }
  134.      
  135.      public static String modify(String exp) {
  136.          //MODIFING ALL FUNCTION WITH A CHARECTER
  137.         exp = exp.replaceAll("sinh", "l");
  138.         exp = exp.replaceAll("cosh", "m");
  139.         exp = exp.replaceAll("tanh", "n");
  140.         exp = exp.replaceAll("asin", "S");
  141.         exp = exp.replaceAll("acos", "C");
  142.         exp = exp.replaceAll("atan", "T");
  143.         exp = exp.replaceAll("sin", "s");
  144.         exp = exp.replaceAll("cos", "c");
  145.         exp = exp.replaceAll("tan", "t");
  146.         exp = exp.replaceAll("log", "l");
  147.         exp = exp.replaceAll("ln", "L");
  148.         exp = exp.replaceAll("sqrt", "r");
  149.         exp = exp.replaceAll("cbrt", "R");
  150.         exp = exp.replaceAll("exp", "x");
  151.         exp = exp.replaceAll("PI", "3.141592654");
  152.         exp = exp.replaceAll("e", "2.7182828");
  153.         return (exp);
  154.  
  155.     }
  156.  
  157.      /// SHUNTING YARD ALGORITHM
  158.     public static double evaluate(String expression) {
  159.        
  160.         System.out.println(expression);
  161.         char[] array = expression.toCharArray();
  162.         Stack<Double> stack = new Stack<Double>();
  163.         Stack<Character> operators = new Stack<Character>();
  164.         try {
  165.             for (int i = 0; i < array.length; i++) {
  166.                 //System.out.println("i:"+i);
  167.                 if (array[0] == '-' && i == 0) {
  168.                     i += 2;
  169.                     StringBuilder x = new StringBuilder();
  170.                     while ((i < array.length) && ((array[i] >= '0' && array[i] <= '9') || (array[i] == '.'))) {
  171.                         x.append(array[i]);
  172.                         i++;
  173.                     }
  174.                     System.out.println(x);
  175.                     String num = "-" + x;
  176.                     System.out.println("NUM:" + num);
  177.                     stack.push(Double.parseDouble(num));
  178.                     if (i >= array.length) {
  179.                         break;
  180.                     }
  181.                 }
  182.                 System.out.println("I:" + i);
  183.                 if (array[i] == ' ') {
  184.                     continue;
  185.                 }
  186.                 if (array[i] >= '0' && array[i] <= '9') {
  187.                     StringBuilder sbuf = new StringBuilder();
  188.                     int check = 0;
  189.                     while ((i < array.length) && ((array[i] >= '0' && array[i] <= '9') || (array[i] == '.'))) {
  190.  
  191.                         if (array[i] == '.') {
  192.                             check++;
  193.                         }
  194.                         ////////////////////////////////////////////////////////////////////                                                    
  195.                         sbuf.append(array[i++]);
  196.                     }
  197.                     /////////////////////////////////////////////////////////////////////////////my
  198.                     if (check > 1) {
  199.                         String msg = "SynTex Error with Dot";
  200.                         JOptionPane.showMessageDialog(null, msg);
  201.                         break;
  202.                     }
  203.                     //System.out.println(sbuf);
  204.                     //System.out.println("i:"+i);
  205.                     stack.push(Double.parseDouble(sbuf.toString()));
  206.  
  207.                 } else if (array[i] == '(') {
  208.                     System.out.println(i + "(");
  209.                     operators.push(array[i]);
  210.                 } else if (array[i] == ')') {
  211.                     System.out.println(i + ")");
  212.                     while (operators.peek() != '(') {
  213.                         char opr = operators.pop();
  214.                         if (advance.isAlpha(opr) == 1) {
  215.                             double res = applyOp(opr, stack.pop(), 1);
  216.                             System.out.println("RES" + res);
  217.                             stack.push(res);
  218.                         } else {
  219.                             double res = applyOp(opr, stack.pop(), stack.pop());
  220.                             System.out.println("RES" + res);
  221.                             stack.push(res);
  222.                         }
  223.                     }
  224.                     operators.pop();
  225.                 } else if (advance.isOperator(array[i]) == 1) {
  226.                     System.out.println("op:" + array[i]);
  227.  
  228.                     while (!operators.empty() && hasPrecedence(array[i]) <= hasPrecedence(operators.peek()) && operators.peek() != '(') {
  229.                         char opr = operators.pop();
  230.                         if (advance.isAlpha(opr) == 1) {
  231.                             double res = applyOp(opr, stack.pop(), 1);
  232.                             System.out.println("RES" + res);
  233.                             stack.push(res);
  234.                         } else {
  235.                             double res = applyOp(opr, stack.pop(), stack.pop());
  236.                             System.out.println("RES" + res);
  237.                             stack.push(res);
  238.                         }
  239.                         System.out.println("STACK TOP:" + stack.peek());
  240.  
  241.                         // stack.push(applyOp(operators.pop(), stack.pop(), stack.pop()));
  242.                     }
  243.                     operators.push(array[i]);
  244.                     System.out.println("OP:" + operators.peek());
  245.                 }
  246.                 //System.out.println(stack.peek());
  247.                 //System.out.println(operators.peek());
  248.             }
  249.             try {
  250.                 while (!operators.empty()) {
  251.                     char opr = operators.pop();
  252.                     if (advance.isAlpha(opr) == 1) {
  253.                         double res = applyOp(opr, stack.pop(), 1);
  254.                         System.out.println("RES" + res);
  255.                         stack.push(res);
  256.                     } else {
  257.                         double res = applyOp(opr, stack.pop(), stack.pop());
  258.                         System.out.println("RES" + res);
  259.                         stack.push(res);
  260.                     }
  261.                     //stack.push(applyOp(operators.pop(), stack.pop(), stack.pop()));
  262.                 }
  263.             } catch (Exception x) {
  264.                 System.out.println("EXCEPTION");
  265.                 return (-123456);
  266.             }
  267.  
  268.            // return stack.pop();
  269.         } catch (Exception e) {
  270.            System.out.println(e);
  271.            return (-123456);
  272.         }
  273.         return stack.pop();
  274.  
  275.     }
  276.  
  277.     public advance() {
  278.         initComponents();
  279.     }
  280.  
  281.     /**
  282.      * This method is called from within the constructor to initialize the form.
  283.      * WARNING: Do NOT modify this code. The content of this method is always
  284.      * regenerated by the Form Editor.
  285.      */
  286.     @SuppressWarnings("unchecked")
  287.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  288.     private void initComponents() {
  289.  
  290.         buttonGroup1 = new javax.swing.ButtonGroup();
  291.         jButton8 = new javax.swing.JButton();
  292.         jButton9 = new javax.swing.JButton();
  293.         jButton10 = new javax.swing.JButton();
  294.         jButton11 = new javax.swing.JButton();
  295.         jButton12 = new javax.swing.JButton();
  296.         jButton13 = new javax.swing.JButton();
  297.         jButton14 = new javax.swing.JButton();
  298.         jButton15 = new javax.swing.JButton();
  299.         jButton16 = new javax.swing.JButton();
  300.         jButton17 = new javax.swing.JButton();
  301.         jButton18 = new javax.swing.JButton();
  302.         jButton19 = new javax.swing.JButton();
  303.         jButton20 = new javax.swing.JButton();
  304.         jButton1 = new javax.swing.JButton();
  305.         jButton2 = new javax.swing.JButton();
  306.         jButton3 = new javax.swing.JButton();
  307.         jButton4 = new javax.swing.JButton();
  308.         jButton5 = new javax.swing.JButton();
  309.         jButton6 = new javax.swing.JButton();
  310.         jButton7 = new javax.swing.JButton();
  311.         jButton24 = new javax.swing.JButton();
  312.         jButton25 = new javax.swing.JButton();
  313.         l1 = new javax.swing.JTextField();
  314.         jLabel1 = new javax.swing.JLabel();
  315.         jButton29 = new javax.swing.JButton();
  316.         jButton31 = new javax.swing.JButton();
  317.         jButton32 = new javax.swing.JButton();
  318.         btnResult = new javax.swing.JButton();
  319.         jButton35 = new javax.swing.JButton();
  320.         jButton36 = new javax.swing.JButton();
  321.         jButton37 = new javax.swing.JButton();
  322.         jButton38 = new javax.swing.JButton();
  323.         btnResult1 = new javax.swing.JButton();
  324.         jButton21 = new javax.swing.JButton();
  325.         jButton22 = new javax.swing.JButton();
  326.         jButton23 = new javax.swing.JButton();
  327.         jButton27 = new javax.swing.JButton();
  328.         jButton28 = new javax.swing.JButton();
  329.         jButton30 = new javax.swing.JButton();
  330.         jButton33 = new javax.swing.JButton();
  331.         jButton34 = new javax.swing.JButton();
  332.         jButton39 = new javax.swing.JButton();
  333.         jButton40 = new javax.swing.JButton();
  334.         t1 = new javax.swing.JTextField();
  335.         jMenuBar1 = new javax.swing.JMenuBar();
  336.         jMenu1 = new javax.swing.JMenu();
  337.         jMenuItem1 = new javax.swing.JMenuItem();
  338.         jMenuItem2 = new javax.swing.JMenuItem();
  339.         jMenuItem3 = new javax.swing.JMenuItem();
  340.  
  341.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  342.         setBackground(new java.awt.Color(0, 255, 0));
  343.         setForeground(new java.awt.Color(255, 51, 51));
  344.         getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
  345.  
  346.         jButton8.setText(" 7");
  347.         jButton8.addActionListener(new java.awt.event.ActionListener() {
  348.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  349.                 jButton8ActionPerformed(evt);
  350.             }
  351.         });
  352.         getContentPane().add(jButton8, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 130, 50, 39));
  353.  
  354.         jButton9.setText(" 8");
  355.         jButton9.addActionListener(new java.awt.event.ActionListener() {
  356.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  357.                 jButton9ActionPerformed(evt);
  358.             }
  359.         });
  360.         getContentPane().add(jButton9, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 130, 50, 39));
  361.  
  362.         jButton10.setText(" 9");
  363.         jButton10.addActionListener(new java.awt.event.ActionListener() {
  364.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  365.                 jButton10ActionPerformed(evt);
  366.             }
  367.         });
  368.         getContentPane().add(jButton10, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 130, 50, 39));
  369.  
  370.         jButton11.setText(" +");
  371.         jButton11.addActionListener(new java.awt.event.ActionListener() {
  372.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  373.                 jButton11ActionPerformed(evt);
  374.             }
  375.         });
  376.         getContentPane().add(jButton11, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 130, 50, 39));
  377.  
  378.         jButton12.setText(" -");
  379.         jButton12.addActionListener(new java.awt.event.ActionListener() {
  380.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  381.                 jButton12ActionPerformed(evt);
  382.             }
  383.         });
  384.         getContentPane().add(jButton12, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 170, 50, 39));
  385.  
  386.         jButton13.setText(" 4");
  387.         jButton13.addActionListener(new java.awt.event.ActionListener() {
  388.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  389.                 jButton13ActionPerformed(evt);
  390.             }
  391.         });
  392.         getContentPane().add(jButton13, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 170, 50, 39));
  393.  
  394.         jButton14.setText(" 5");
  395.         jButton14.addActionListener(new java.awt.event.ActionListener() {
  396.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  397.                 jButton14ActionPerformed(evt);
  398.             }
  399.         });
  400.         getContentPane().add(jButton14, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 170, 50, 39));
  401.  
  402.         jButton15.setText(" 6");
  403.         jButton15.addActionListener(new java.awt.event.ActionListener() {
  404.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  405.                 jButton15ActionPerformed(evt);
  406.             }
  407.         });
  408.         getContentPane().add(jButton15, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 170, 50, 39));
  409.  
  410.         jButton16.setText(" *");
  411.         jButton16.addActionListener(new java.awt.event.ActionListener() {
  412.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  413.                 jButton16ActionPerformed(evt);
  414.             }
  415.         });
  416.         getContentPane().add(jButton16, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 210, 50, 39));
  417.  
  418.         jButton17.setText(" 1");
  419.         jButton17.addActionListener(new java.awt.event.ActionListener() {
  420.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  421.                 jButton17ActionPerformed(evt);
  422.             }
  423.         });
  424.         getContentPane().add(jButton17, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 210, 50, 39));
  425.  
  426.         jButton18.setText(" 2");
  427.         jButton18.addActionListener(new java.awt.event.ActionListener() {
  428.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  429.                 jButton18ActionPerformed(evt);
  430.             }
  431.         });
  432.         getContentPane().add(jButton18, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 210, 50, 39));
  433.  
  434.         jButton19.setText(" 3");
  435.         jButton19.addActionListener(new java.awt.event.ActionListener() {
  436.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  437.                 jButton19ActionPerformed(evt);
  438.             }
  439.         });
  440.         getContentPane().add(jButton19, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 210, 50, 39));
  441.  
  442.         jButton20.setText(" )");
  443.         jButton20.addActionListener(new java.awt.event.ActionListener() {
  444.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  445.                 jButton20ActionPerformed(evt);
  446.             }
  447.         });
  448.         getContentPane().add(jButton20, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 290, 50, 39));
  449.  
  450.         jButton1.setText(" sin");
  451.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  452.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  453.                 jButton1ActionPerformed(evt);
  454.             }
  455.         });
  456.         getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 130, 60, 39));
  457.  
  458.         jButton2.setText(" cos");
  459.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  460.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  461.                 jButton2ActionPerformed(evt);
  462.             }
  463.         });
  464.         getContentPane().add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 130, 60, 39));
  465.  
  466.         jButton3.setText(" tan");
  467.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  468.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  469.                 jButton3ActionPerformed(evt);
  470.             }
  471.         });
  472.         getContentPane().add(jButton3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 130, 60, 39));
  473.  
  474.         jButton4.setText(" sqrt");
  475.         jButton4.addActionListener(new java.awt.event.ActionListener() {
  476.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  477.                 jButton4ActionPerformed(evt);
  478.             }
  479.         });
  480.         getContentPane().add(jButton4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, 60, 39));
  481.  
  482.         jButton5.setText(" x!");
  483.         jButton5.addActionListener(new java.awt.event.ActionListener() {
  484.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  485.                 jButton5ActionPerformed(evt);
  486.             }
  487.         });
  488.         getContentPane().add(jButton5, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 210, 60, 39));
  489.  
  490.         jButton6.setText(" atan");
  491.         jButton6.addActionListener(new java.awt.event.ActionListener() {
  492.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  493.                 jButton6ActionPerformed(evt);
  494.             }
  495.         });
  496.         getContentPane().add(jButton6, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 250, 60, 39));
  497.  
  498.         jButton7.setText(" exp");
  499.         jButton7.addActionListener(new java.awt.event.ActionListener() {
  500.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  501.                 jButton7ActionPerformed(evt);
  502.             }
  503.         });
  504.         getContentPane().add(jButton7, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 170, 60, 39));
  505.  
  506.         jButton24.setText(" log");
  507.         jButton24.addActionListener(new java.awt.event.ActionListener() {
  508.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  509.                 jButton24ActionPerformed(evt);
  510.             }
  511.         });
  512.         getContentPane().add(jButton24, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 170, 60, 39));
  513.  
  514.         jButton25.setText(" ln");
  515.         jButton25.addActionListener(new java.awt.event.ActionListener() {
  516.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  517.                 jButton25ActionPerformed(evt);
  518.             }
  519.         });
  520.         getContentPane().add(jButton25, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 170, 60, 39));
  521.  
  522.         l1.setEditable(false);
  523.         l1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
  524.         l1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
  525.         l1.setText(" ");
  526.         l1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
  527.         l1.addActionListener(new java.awt.event.ActionListener() {
  528.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  529.                 l1ActionPerformed(evt);
  530.             }
  531.         });
  532.         getContentPane().add(l1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 0, 450, 40));
  533.  
  534.         jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
  535.         jLabel1.setText("RESULT :");
  536.         getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 54, 160, 30));
  537.  
  538.         jButton29.setText(" RESET");
  539.         jButton29.addActionListener(new java.awt.event.ActionListener() {
  540.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  541.                 jButton29ActionPerformed(evt);
  542.             }
  543.         });
  544.         getContentPane().add(jButton29, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 330, 100, 39));
  545.  
  546.         jButton31.setText(" (");
  547.         jButton31.addActionListener(new java.awt.event.ActionListener() {
  548.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  549.                 jButton31ActionPerformed(evt);
  550.             }
  551.         });
  552.         getContentPane().add(jButton31, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 290, 50, 39));
  553.  
  554.         jButton32.setText(" EXIT");
  555.         jButton32.addActionListener(new java.awt.event.ActionListener() {
  556.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  557.                 jButton32ActionPerformed(evt);
  558.             }
  559.         });
  560.         getContentPane().add(jButton32, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 330, 100, 39));
  561.  
  562.         btnResult.setText(" =");
  563.         btnResult.addActionListener(new java.awt.event.ActionListener() {
  564.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  565.                 btnResultActionPerformed(evt);
  566.             }
  567.         });
  568.         getContentPane().add(btnResult, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 290, 50, 39));
  569.  
  570.         jButton35.setText(" <-");
  571.         jButton35.addActionListener(new java.awt.event.ActionListener() {
  572.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  573.                 jButton35ActionPerformed(evt);
  574.             }
  575.         });
  576.         getContentPane().add(jButton35, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 290, 50, 39));
  577.  
  578.         jButton36.setText(" /");
  579.         jButton36.addActionListener(new java.awt.event.ActionListener() {
  580.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  581.                 jButton36ActionPerformed(evt);
  582.             }
  583.         });
  584.         getContentPane().add(jButton36, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 250, 50, 39));
  585.  
  586.         jButton37.setText(" .");
  587.         jButton37.addActionListener(new java.awt.event.ActionListener() {
  588.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  589.                 jButton37ActionPerformed(evt);
  590.             }
  591.         });
  592.         getContentPane().add(jButton37, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 250, 50, 39));
  593.  
  594.         jButton38.setText(" 0");
  595.         jButton38.addActionListener(new java.awt.event.ActionListener() {
  596.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  597.                 jButton38ActionPerformed(evt);
  598.             }
  599.         });
  600.         getContentPane().add(jButton38, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 250, 50, 39));
  601.  
  602.         btnResult1.setText(" ^");
  603.         btnResult1.addActionListener(new java.awt.event.ActionListener() {
  604.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  605.                 btnResult1ActionPerformed(evt);
  606.             }
  607.         });
  608.         getContentPane().add(btnResult1, new org.netbeans.lib.awtextra.AbsoluteConstraints(400, 250, 50, 39));
  609.  
  610.         jButton21.addActionListener(new java.awt.event.ActionListener() {
  611.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  612.                 jButton21ActionPerformed(evt);
  613.             }
  614.         });
  615.         getContentPane().add(jButton21, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 370, 420, 40));
  616.  
  617.         jButton22.setText(" ANS");
  618.         jButton22.addActionListener(new java.awt.event.ActionListener() {
  619.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  620.                 jButton22ActionPerformed(evt);
  621.             }
  622.         });
  623.         getContentPane().add(jButton22, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 330, 60, 40));
  624.  
  625.         jButton23.setText(" cbrt");
  626.         jButton23.addActionListener(new java.awt.event.ActionListener() {
  627.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  628.                 jButton23ActionPerformed(evt);
  629.             }
  630.         });
  631.         getContentPane().add(jButton23, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 210, 60, 39));
  632.  
  633.         jButton27.setText(" asin");
  634.         jButton27.addActionListener(new java.awt.event.ActionListener() {
  635.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  636.                 jButton27ActionPerformed(evt);
  637.             }
  638.         });
  639.         getContentPane().add(jButton27, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 250, 60, 39));
  640.  
  641.         jButton28.setText(" acos");
  642.         jButton28.addActionListener(new java.awt.event.ActionListener() {
  643.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  644.                 jButton28ActionPerformed(evt);
  645.             }
  646.         });
  647.         getContentPane().add(jButton28, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 250, 60, 39));
  648.  
  649.         jButton30.setText("  e");
  650.         jButton30.addActionListener(new java.awt.event.ActionListener() {
  651.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  652.                 jButton30ActionPerformed(evt);
  653.             }
  654.         });
  655.         getContentPane().add(jButton30, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 330, 60, 39));
  656.  
  657.         jButton33.setText(" PI");
  658.         jButton33.addActionListener(new java.awt.event.ActionListener() {
  659.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  660.                 jButton33ActionPerformed(evt);
  661.             }
  662.         });
  663.         getContentPane().add(jButton33, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 330, 60, 39));
  664.  
  665.         jButton34.setText(" sinh");
  666.         jButton34.addActionListener(new java.awt.event.ActionListener() {
  667.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  668.                 jButton34ActionPerformed(evt);
  669.             }
  670.         });
  671.         getContentPane().add(jButton34, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 290, 60, 39));
  672.  
  673.         jButton39.setText(" cosh");
  674.         jButton39.addActionListener(new java.awt.event.ActionListener() {
  675.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  676.                 jButton39ActionPerformed(evt);
  677.             }
  678.         });
  679.         getContentPane().add(jButton39, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 290, 60, 39));
  680.  
  681.         jButton40.setText(" tanh");
  682.         jButton40.addActionListener(new java.awt.event.ActionListener() {
  683.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  684.                 jButton40ActionPerformed(evt);
  685.             }
  686.         });
  687.         getContentPane().add(jButton40, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 290, 60, 39));
  688.  
  689.         t1.addActionListener(new java.awt.event.ActionListener() {
  690.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  691.                 t1ActionPerformed(evt);
  692.             }
  693.         });
  694.         getContentPane().add(t1, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 50, 240, 40));
  695.  
  696.         jMenu1.setText("Option");
  697.  
  698.         jMenuItem1.setText("Normal Calculator");
  699.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  700.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  701.                 jMenuItem1ActionPerformed(evt);
  702.             }
  703.         });
  704.         jMenu1.add(jMenuItem1);
  705.  
  706.         jMenuItem2.setText("Scientific Calculator");
  707.         jMenu1.add(jMenuItem2);
  708.  
  709.         jMenuItem3.setText("Conversion");
  710.         jMenu1.add(jMenuItem3);
  711.  
  712.         jMenuBar1.add(jMenu1);
  713.  
  714.         setJMenuBar(jMenuBar1);
  715.  
  716.         pack();
  717.     }// </editor-fold>                        
  718.  
  719.     private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  720.         String s;
  721.         s = (l1.getText()) + "8";
  722.  
  723.         l1.setText(s);        // TODO add your handling code here:
  724.     }                                        
  725.  
  726.     private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  727.         String s;
  728.         s = (l1.getText()) + "9";
  729.  
  730.         l1.setText(s);        // TODO add your handling code here:
  731.     }                                        
  732.  
  733.     private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  734.         String s;
  735.         s = (l1.getText()) + " + ";
  736.         l1.setText(s);           // TODO add your handling code here:
  737.     }                                        
  738.  
  739.     private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  740.         String s;
  741.         s = (l1.getText()) + " - ";
  742.         l1.setText(s);           // TODO add your handling code here:
  743.     }                                        
  744.  
  745.     private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  746.         String s;
  747.         s = (l1.getText()) + "5";
  748.  
  749.         l1.setText(s);        // TODO add your handling code here:
  750.     }                                        
  751.  
  752.     private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  753.         String s;
  754.         s = (l1.getText()) + "6";
  755.  
  756.         l1.setText(s);        // TODO add your handling code here:
  757.     }                                        
  758.  
  759.     private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  760.         String s;
  761.         s = (l1.getText()) + " * ";
  762.         l1.setText(s);           // TODO add your handling code here:
  763.     }                                        
  764.  
  765.     private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  766.         String s;
  767.         s = (l1.getText()) + "2";
  768.  
  769.         l1.setText(s);        // TODO add your handling code here:
  770.     }                                        
  771.  
  772.     private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  773.         String s;
  774.         s = (l1.getText()) + "3";
  775.  
  776.         l1.setText(s);        // TODO add your handling code here:
  777.     }                                        
  778.  
  779.     private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  780.         String s;
  781.         s = (l1.getText()) + " ) ";
  782.         l1.setText(s);           // TODO add your handling code here:
  783.     }                                        
  784.  
  785.     private void jButton29ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  786.         //this.getContentPane().setBackground(Color.blue);
  787.         l1.setText("");
  788.         t1.setText("");// TODO add your handling code here:
  789.     }                                        
  790.  
  791.     private void jButton32ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  792.         System.exit(0);        // TODO add your handling code here:
  793.     }                                        
  794.  
  795.     private void btnResultActionPerformed(java.awt.event.ActionEvent evt) {                                          
  796.         String cmd;
  797.         StringBuilder exp = new StringBuilder(1000);
  798.         String s = l1.getText();
  799.         System.out.println(s.length());
  800.         if (s.length() > 1) {
  801.             exp.append(s);
  802.             int i, flag = 0, start = -1, end = -1;
  803.             float ans = 0f;
  804.             //   REDUCING THE COMPLEX EQUATION
  805.             String str = advance.modify(exp.toString());
  806.             //    EQUATION SIMPLIFIED
  807.             System.out.println(exp);
  808.             // CALL EVALUATE FOR THE RESULT
  809.             float res = (float) advance.evaluate(str.trim());
  810.             if (res != -123456) {
  811.                 System.out.println(res);
  812.                 t1.setText("" + res);
  813.                 memory = t1.getText();
  814.             } else
  815.             {
  816.                 JOptionPane.showMessageDialog(null, "YOUR SYNTAX IS WRONG!");
  817.             }
  818.  
  819.         }
  820.     }                                        
  821.  
  822.     private void jButton35ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  823. ////////////////////////////////////code for backspace
  824.         String s, str;
  825.         s = l1.getText();
  826.         int l = s.length();
  827.         if (l > 0) {
  828.             l1.setText("");
  829.             str = s.substring(0, l - 1);
  830.             l1.setText(str);
  831.         }// TODO add your handling code here:
  832.     }                                        
  833.  
  834.     private void jButton36ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  835.         String s;
  836.         s = (l1.getText()) + " / ";
  837.         l1.setText(s);         // TODO add your handling code here:
  838.     }                                        
  839.  
  840.     private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  841.         String s;
  842.         s = (l1.getText()) + "1";
  843.  
  844.         l1.setText(s);        // TODO add your handling code here:
  845.     }                                        
  846.  
  847.     private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  848.         String s;
  849.         s = (l1.getText()) + "4";
  850.  
  851.         l1.setText(s);        // TODO add your handling code here:
  852.     }                                        
  853.  
  854.     private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  855.         String s;
  856.         s = (l1.getText()) + "7";
  857.  
  858.         l1.setText(s);        // TODO add your handling code here:
  859.     }                                        
  860.  
  861.     private void jButton37ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  862.         String s;
  863.         s = (l1.getText()) + ".";
  864.         l1.setText(s);           // TODO add your handling code here:
  865.     }                                        
  866.  
  867.     private void jButton31ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  868.         String s;
  869.         s = (l1.getText()) + " ( ";
  870.         l1.setText(s);           // TODO add your handling code here:
  871.     }                                        
  872.  
  873.     private void jButton38ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  874.         String s;
  875.         s = (l1.getText()) + "0";
  876.         l1.setText(s);         // TODO add your handling code here:
  877.     }                                        
  878.  
  879.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  880.         String s;
  881.         s = (l1.getText()) + "sin( ";
  882.  
  883.         l1.setText(s);          // TODO add your handling code here:
  884.     }                                        
  885.  
  886.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  887.         String s;
  888.         s = (l1.getText()) + "cos( ";
  889.  
  890.         l1.setText(s);          // TODO add your handling code here:
  891.     }                                        
  892.  
  893.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  894.         String s;
  895.         s = (l1.getText()) + "tan( ";
  896.  
  897.         l1.setText(s);          // TODO add your handling code here:
  898.     }                                        
  899.  
  900.     private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  901.         String s;
  902.         s = (l1.getText()) + "exp( ";
  903.  
  904.         l1.setText(s);          // TODO add your handling code here:
  905.     }                                        
  906.  
  907.     private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  908.         String s;
  909.         s = (l1.getText()) + "log( ";
  910.  
  911.         l1.setText(s);          // TODO add your handling code here:
  912.     }                                        
  913.  
  914.     private void jButton25ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  915.         String s;
  916.         s = (l1.getText()) + "ln( ";
  917.  
  918.         l1.setText(s);          // TODO add your handling code here:
  919.     }                                        
  920.  
  921.     private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  922.         String s;
  923.         s = (l1.getText()) + "sqrt( ";
  924.  
  925.         l1.setText(s);          // TODO add your handling code here:
  926.     }                                        
  927.  
  928.     private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  929.         String s;
  930.         s = (l1.getText()) + " ! ";
  931.  
  932.         l1.setText(s);          // TODO add your handling code here:
  933.     }                                        
  934.  
  935.     private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  936.         String s;
  937.         s = (l1.getText()) + "atan( ";
  938.  
  939.         l1.setText(s);          // TODO add your handling code here:
  940.     }                                        
  941.  
  942.     private void btnResult1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  943.         String s;
  944.         s = (l1.getText()) + " ^ ";
  945.  
  946.         l1.setText(s);   // TODO add your handling code here:
  947.     }                                          
  948.  
  949.     private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  950. ///////////////ToDo code
  951.     }                                        
  952.  
  953.     private void jButton22ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  954.         /*new choice().setVisible(true);
  955.     this.setVisible(false);// TODO add your handling code here:
  956.          */
  957.         String s = l1.getText();
  958.         l1.setText(s + memory);
  959.     }                                        
  960.  
  961.     private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  962.         String s;
  963.         s = (l1.getText()) + "cbrt( ";
  964.  
  965.         l1.setText(s);               // TODO add your handling code here:
  966.     }                                        
  967.  
  968.     private void jButton27ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  969.         String s;
  970.         s = (l1.getText()) + "asin( ";
  971.  
  972.         l1.setText(s);          // TODO add your handling code here:
  973.     }                                        
  974.  
  975.     private void jButton28ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  976.         String s;
  977.         s = (l1.getText()) + "acos( ";
  978.  
  979.         l1.setText(s);          // TODO add your handling code here:
  980.     }                                        
  981.  
  982.     private void jButton30ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  983.         String s;
  984.         s = (l1.getText()) + " e ";
  985.  
  986.         l1.setText(s);          // TODO add your handling code here:
  987.     }                                        
  988.  
  989.     private void jButton33ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  990.         String s;
  991.         s = (l1.getText()) + " PI ";
  992.  
  993.         l1.setText(s);          // TODO add your handling code here:
  994.     }                                        
  995.  
  996.     private void jButton34ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  997.         // TODO add your handling code here:
  998.         String s;
  999.         s = (l1.getText()) + " sinh ";
  1000.  
  1001.         l1.setText(s);
  1002.     }                                        
  1003.  
  1004.     private void jButton39ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  1005.         // TODO add your handling code here:
  1006.         String s;
  1007.         s = (l1.getText()) + " cosh ";
  1008.  
  1009.         l1.setText(s);
  1010.     }                                        
  1011.  
  1012.     private void jButton40ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  1013.         // TODO add your handling code here:
  1014.         String s;
  1015.         s = (l1.getText()) + " tanh ";
  1016.  
  1017.         l1.setText(s);
  1018.     }                                        
  1019.  
  1020.     private void l1ActionPerformed(java.awt.event.ActionEvent evt) {                                  
  1021.         // TODO add your handling code here:
  1022.     }                                  
  1023.  
  1024.     private void t1ActionPerformed(java.awt.event.ActionEvent evt) {                                  
  1025.         // TODO add your handling code here:
  1026.     }                                  
  1027.  
  1028.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  1029.         // TODO add your handling code here:
  1030.         new Scientific_Calculator().setVisible(true);
  1031.         this.setVisible(false);
  1032.     }                                          
  1033.  
  1034.     /**
  1035.      * @param args the command line arguments
  1036.      */
  1037.     public static void main(String args[]) {
  1038.  
  1039.         /* Create and display the form */
  1040.         java.awt.EventQueue.invokeLater(new Runnable() {
  1041.             public void run() {
  1042.  
  1043.                 new advance().setVisible(true);
  1044.             }
  1045.         });
  1046.     }
  1047.  
  1048.     // Variables declaration - do not modify                    
  1049.     private javax.swing.JButton btnResult;
  1050.     private javax.swing.JButton btnResult1;
  1051.     private javax.swing.ButtonGroup buttonGroup1;
  1052.     private javax.swing.JButton jButton1;
  1053.     private javax.swing.JButton jButton10;
  1054.     private javax.swing.JButton jButton11;
  1055.     private javax.swing.JButton jButton12;
  1056.     private javax.swing.JButton jButton13;
  1057.     private javax.swing.JButton jButton14;
  1058.     private javax.swing.JButton jButton15;
  1059.     private javax.swing.JButton jButton16;
  1060.     private javax.swing.JButton jButton17;
  1061.     private javax.swing.JButton jButton18;
  1062.     private javax.swing.JButton jButton19;
  1063.     private javax.swing.JButton jButton2;
  1064.     private javax.swing.JButton jButton20;
  1065.     private javax.swing.JButton jButton21;
  1066.     private javax.swing.JButton jButton22;
  1067.     private javax.swing.JButton jButton23;
  1068.     private javax.swing.JButton jButton24;
  1069.     private javax.swing.JButton jButton25;
  1070.     private javax.swing.JButton jButton27;
  1071.     private javax.swing.JButton jButton28;
  1072.     private javax.swing.JButton jButton29;
  1073.     private javax.swing.JButton jButton3;
  1074.     private javax.swing.JButton jButton30;
  1075.     private javax.swing.JButton jButton31;
  1076.     private javax.swing.JButton jButton32;
  1077.     private javax.swing.JButton jButton33;
  1078.     private javax.swing.JButton jButton34;
  1079.     private javax.swing.JButton jButton35;
  1080.     private javax.swing.JButton jButton36;
  1081.     private javax.swing.JButton jButton37;
  1082.     private javax.swing.JButton jButton38;
  1083.     private javax.swing.JButton jButton39;
  1084.     private javax.swing.JButton jButton4;
  1085.     private javax.swing.JButton jButton40;
  1086.     private javax.swing.JButton jButton5;
  1087.     private javax.swing.JButton jButton6;
  1088.     private javax.swing.JButton jButton7;
  1089.     private javax.swing.JButton jButton8;
  1090.     private javax.swing.JButton jButton9;
  1091.     private javax.swing.JLabel jLabel1;
  1092.     private javax.swing.JMenu jMenu1;
  1093.     private javax.swing.JMenuBar jMenuBar1;
  1094.     private javax.swing.JMenuItem jMenuItem1;
  1095.     private javax.swing.JMenuItem jMenuItem2;
  1096.     private javax.swing.JMenuItem jMenuItem3;
  1097.     private javax.swing.JTextField l1;
  1098.     private javax.swing.JTextField t1;
  1099.     // End of variables declaration                  
  1100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement