ppt on scientific calculator project in java
#1

Need calculator project only  documentation ,not a source code ,could you please provide the documentation.
Reply
#2
scientific calculator using the event-driven programming paradigm of Java:

Code:
   import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class Calculator extends JFrame {
   private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20);
   private JTextField textfield;
   private boolean number = true;
   private String equalOp = "=";
   private CalculatorOp op = new CalculatorOp();
   
   public Calculator() {
       textfield = new JTextField("", 12);
       textfield.setHorizontalAlignment(JTextField.RIGHT);
       textfield.setFont(BIGGER_FONT);
       ActionListener numberListener = new NumberListener();
       String buttonOrder = "1234567890 ";
       JPanel buttonPanel = new JPanel();
       buttonPanel.setLayout(new GridLayout(4, 4, 4, 4));
       for (int i = 0; i < buttonOrder.length(); i++) {
           String key = buttonOrder.substring(i, i+1);
           if (key.equals(" ")) {
               buttonPanel.add(new JLabel(""));
           } else {
               JButton button = new JButton(key);
               button.addActionListener(numberListener);
               button.setFont(BIGGER_FONT);
               buttonPanel.add(button);
           }
       }
       ActionListener operatorListener = new OperatorListener();
       JPanel panel = new JPanel();
       panel.setLayout(new GridLayout(4, 4, 4, 4));
       String[] opOrder = {"+", "-", "*", "/","=","C","sin","cos","log"};
       for (int i = 0; i < opOrder.length; i++) {
           JButton button = new JButton(opOrder[i]);
           button.addActionListener(operatorListener);
           button.setFont(BIGGER_FONT);
           panel.add(button);
       }
       JPanel pan = new JPanel();
       pan.setLayout(new BorderLayout(4, 4));
       pan.add(textfield, BorderLayout.NORTH );
       pan.add(buttonPanel , BorderLayout.CENTER);
       pan.add(panel , BorderLayout.EAST);
       this.setContentPane(pan);
       this.pack();
       this.setTitle("Calculator");
       this.setResizable(false);
   }
   private void action() {
       number = true;
       textfield.setText("");
       equalOp = "=";
       op.setTotal("");
   }
   class OperatorListener implements ActionListener {
       public void actionPerformed(ActionEvent e) {
           String displayText = textfield.getText();
           if (e.getActionCommand().equals("sin"))
           {
               textfield.setText("" + Math.sin(Double.valueOf(displayText).doubleValue()));
               
           }else
           if (e.getActionCommand().equals("cos"))
           {
               textfield.setText("" + Math.cos(Double.valueOf(displayText).doubleValue()));
               
           }
           else
           if (e.getActionCommand().equals("log"))
           {
               textfield.setText("" + Math.log(Double.valueOf(displayText).doubleValue()));
               
           }
           else if (e.getActionCommand().equals("C"))
           {
               textfield.setText("");
           }

           else
           {
               if (number)
               {
                   
                   action();
                   textfield.setText("");
                   
               }
               else
               {
                   number = true;
                   if (equalOp.equals("="))
                   {
                       op.setTotal(displayText);
                   }else
                   if (equalOp.equals("+"))
                   {
                       op.add(displayText);
                   }
                   else if (equalOp.equals("-"))
                   {
                       op.subtract(displayText);
                   }
                   else if (equalOp.equals("*"))
                   {
                       op.multiply(displayText);
                   }
                   else if (equalOp.equals("/"))
                   {
                       op.divide(displayText);
                   }
                   
                   textfield.setText("" + op.getTotalString());
                   equalOp = e.getActionCommand();
               }
           }
       }
   }
   class NumberListener implements ActionListener {
       public void actionPerformed(ActionEvent event) {
           String digit = event.getActionCommand();
           if (number) {
               textfield.setText(digit);
               number = false;
           } else {
               textfield.setText(textfield.getText() + digit);
           }
       }
   }
   public class CalculatorOp {
       private int total;
       public CalculatorOp() {
           total = 0;
       }
       public String getTotalString() {
           return ""+total;
       }
       public void setTotal(String n) {
           total = convertToNumber(n);
       }
       public void add(String n) {
           total += convertToNumber(n);
       }
       public void subtract(String n) {
           total -= convertToNumber(n);
       }
       public void multiply(String n) {
           total *= convertToNumber(n);
       }
       public void divide(String n) {
           total /= convertToNumber(n);
       }
       private int convertToNumber(String n) {
           return Integer.parseInt(n);
       }
   }
}
class SwingCalculator {
   public static void main(String[] args) {
       JFrame frame = new Calculator();
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setVisible(true);
   }
}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: project on the scientific method, source code of calculator in java, scientific calculator project abstract, report on scientific calculator in java ppt, java mini projects with source code for scientific calculator, scientific calculator using c ppt, scientific calculator presentation in java,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  program for ticket reservation using multithreading in java 0 1,140 08-10-2018, 10:00 AM
Last Post: Guest
  ppt of scientific calculator with e r diagram 1 1,032 05-10-2018, 12:18 AM
Last Post: Guest
  online mobile recharge project ppt 0 937 02-10-2018, 02:24 PM
Last Post: Guest
  icse java projects class 10 free download 0 902 25-09-2018, 10:32 PM
Last Post: Guest
  java source code for voice based email for blinds 0 782 25-09-2018, 09:40 AM
Last Post: Guest
  techmax core java book pdf download 0 701 20-09-2018, 12:54 PM
Last Post: Guest
  shares and dividend maths project icse ppt 0 866 20-08-2018, 12:59 PM
Last Post: Guest
  rnsit java notes download 0 806 08-08-2018, 10:23 PM
Last Post: Guest
  image steganography source code in java pdf 0 805 04-08-2018, 09:38 PM
Last Post: Guest
  download prisoner face identification system in java source code 0 557 02-08-2018, 01:28 PM
Last Post: Guest

Forum Jump: