I have no idea what wrong my cods when I press = button of my calculator nothing happens.

import java.util.Stack;
import java.util.Stack;
 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import java.math.*;
 import java.util.Vector;
 

public class Ahsan extends JFrame{
 Stack s = new Stack();
 
private JFrame f;
 private JPanel p1,p2;
 private JTextField jtfMain;
 private JButton jbtnOn, jbtnMRC, jbtnMminus, jbtnMadd, jbtnDivide, jbtnOff, jbtnSeven, jbtnEight, jbtnNine, jbtnMultiply,
 jbtnSqrt, jbtnFour, jbtnFive, jbtnSix, jbtnMinus, jbtnSq, jbtnOne, jbtnTwo, jbtnThree, jbtnPlus, jbtn1x, jbtnZero, jbtnDecimal,
 jbtnEqual, jbtnEnter;
 
char ch;
 Stack<String> cStack=new Stack<String>();
 public Ahsan() {
 


setSize(400,190);
 setTitle("Reverse Polish Notation Calculator");
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 setLayout(new BorderLayout());
 
jtfMain = new JTextField("");
 
jbtnOn = new JButton("ON/AC");
 jbtnMRC = new JButton("MRC");
 jbtnMminus = new JButton("M-");
 jbtnMadd = new JButton("M+");
 jbtnDivide = new JButton("/");
 jbtnOff = new JButton("OFF");
 jbtnSeven = new JButton("7");
 jbtnEight = new JButton("8");
 jbtnNine = new JButton("9");
 jbtnMultiply = new JButton("X");
 jbtnSqrt = new JButton("SQRT");
 jbtnFour = new JButton("4");
 jbtnFive = new JButton("5");
 jbtnSix = new JButton("6");
 jbtnMinus = new JButton("-");
 jbtnSq = new JButton("SQ");
 jbtnOne = new JButton("1");
 jbtnTwo = new JButton("2");
 jbtnThree = new JButton("3");
 jbtnPlus = new JButton("+");
 jbtn1x = new JButton("1/x");
 jbtnZero = new JButton("0");
 jbtnDecimal = new JButton(".");
 jbtnEqual = new JButton("=");
 jbtnEnter = new JButton("ENTER");
 
p1 = new JPanel();
 p1.setLayout(new GridLayout(1,1));
 
p2 = new JPanel();
 p2.setLayout(new GridLayout(5,5));
 
p1.add(jtfMain);
 
p2.add(jbtnOn);
 p2.add(jbtnMRC);
 p2.add(jbtnMadd);
 p2.add(jbtnMminus);
 p2.add(jbtnDivide);
 p2.add(jbtnSeven);
 p2.add(jbtnEight);
 p2.add(jbtnNine);
 p2.add(jbtnMultiply);
 p2.add(jbtnSqrt);
 p2.add(jbtnFour);
 p2.add(jbtnFive);
 p2.add(jbtnSix);
 p2.add(jbtnMinus);
 p2.add(jbtnSq);
 p2.add(jbtnOne);
 p2.add(jbtnTwo);
 p2.add(jbtnThree);
 p2.add(jbtnPlus);
 p2.add(jbtn1x);
 p2.add(jbtnZero);
 p2.add(jbtnDecimal);
 p2.add(jbtnEqual);
 p2.add(jbtnEnter);
 p2.add(jbtnOff);
 
ButtonHandler buttonHandler=new ButtonHandler();
 jbtnOn.addActionListener(new ButtonHandler());
 jbtnMRC.addActionListener(new ButtonHandler());
 jbtnMminus.addActionListener(new ButtonHandler());
 jbtnDivide.addActionListener(new ButtonHandler());
 jbtnOff.addActionListener(new ButtonHandler());
 jbtnSeven.addActionListener(new ButtonHandler());
 jbtnEight.addActionListener(new ButtonHandler());
 jbtnNine.addActionListener(new ButtonHandler());
 jbtnMultiply.addActionListener(new ButtonHandler());
 jbtnSqrt.addActionListener(new ButtonHandler());
 jbtnFour.addActionListener(new ButtonHandler());
 jbtnFive.addActionListener(new ButtonHandler());
 jbtnSix.addActionListener(new ButtonHandler());
 jbtnMinus.addActionListener(new ButtonHandler());
 jbtnSq.addActionListener(new ButtonHandler());
 jbtnOne.addActionListener(new ButtonHandler());
 jbtnTwo.addActionListener(new ButtonHandler());
 jbtnThree.addActionListener(new ButtonHandler());
 jbtnPlus.addActionListener(new ButtonHandler());
 jbtn1x.addActionListener(new ButtonHandler());
 jbtnZero.addActionListener(new ButtonHandler());
 jbtnDecimal.addActionListener(new ButtonHandler());
 jbtnEqual.addActionListener(new ButtonHandler());
 jbtnEnter.addActionListener(new ButtonHandler());
 
add(p1, BorderLayout.NORTH);
 add(p2, BorderLayout.CENTER);
 
setVisible(true);
 }
 
public class enterHandler implements ActionListener
 {
 public void actionPerformed(ActionEvent evt)
 {
 int a;
 int b;
 
if (evt.getSource() == jbtnEnter)
 {
 //JButton hooked = (JButton) evt.getSource();
 
jtfMain.setText(jtfMain.getText() + " ");
 
String value = jtfMain.getText();
 
//if(value.lastIndexOf().equals("+"))
 //{
 String [] itemValue = value.split(" ");
 //System.out.println(itemValue.length);
 
for (int i=0;i<itemValue.length;i++)
 {
 cStack.push(itemValue[i]);
 }
 

if(cStack.pop().equals("+"))
 {
 
BigInteger first = new BigInteger(cStack.pop());
 BigInteger second = new BigInteger(cStack.pop());
 
first = first.add(second);
 cStack.push(first + "");
 }
 if(cStack.pop().equals("-"))
 {
 
BigInteger first = new BigInteger(cStack.pop());
 BigInteger second = new BigInteger(cStack.pop());
 
first = first.subtract(second);
 cStack.push(first + "");
 }
 
/*else if(cStack.pop().equals("-"))
 {
 BigInteger first = new BigInteger(cStack.pop());
 BigInteger second = new BigInteger(cStack.pop());
 
first = first.subtract(second);
 cStack.push(first + "");
 }*/
 //jtfMain.setText(cStack.pop());
 /*switch(ch)
 {
 case "/" : a = first.divide(second);
 }*/
 }
 }
 
}
 //}
 
public class ButtonHandler implements ActionListener
 {
 public void actionPerformed(ActionEvent evt)
 {
 JButton clicked = (JButton) evt.getSource();
 
if(clicked == jbtnOn)
 {
 jtfMain.setText("");
 }
 else if(clicked == jbtnOne)
 {
 jtfMain.setText(jtfMain.getText() + "1");
 //cStack.push(1);
 }
 else if(clicked== jbtnTwo)
 {
 jtfMain.setText(jtfMain.getText() + "2");
 //cStack.push(2);
 }
 else if(clicked== jbtnThree)
 {
 jtfMain.setText(jtfMain.getText() + "3");
 //cStack.push(3);
 }
 else if(clicked== jbtnFour)
 {
 jtfMain.setText(jtfMain.getText() + "4");
 //cStack.push(4);
 }
 else if(clicked== jbtnFive)
 {
 jtfMain.setText(jtfMain.getText() + "5");
 //cStack.push(5);
 }
 else if(clicked== jbtnSix)
 {
 jtfMain.setText(jtfMain.getText() + "6");
 //cStack.push(6);
 }
 else if(clicked== jbtnSeven)
 {
 jtfMain.setText(jtfMain.getText() + "7");
 //cStack.push(7);
 }
 else if(clicked== jbtnEight)
 {
 jtfMain.setText(jtfMain.getText() + "8");
 //cStack.push(8);
 }
 else if(clicked == jbtnNine)
 {
 jtfMain.setText(jtfMain.getText() + "9");
 //cStack.push(9);
 }
 else if(clicked == jbtnZero)
 {
 jtfMain.setText(jtfMain.getText() + "0");
 //add.numbers[];
 }
 else if(clicked == jbtnDivide)
 {
 jtfMain.setText(jtfMain.getText() + "/");
 //ch = '/';
 }
 
else if(clicked== jbtnMultiply)
 {
 jtfMain.setText(jtfMain.getText() + "X");
 
}
 else if(clicked== jbtnPlus)
 {
 jtfMain.setText(jtfMain.getText() + "+");
 //ch = 'a';
 }
 else if(clicked== jbtnMinus)
 {
 jtfMain.setText(jtfMain.getText() + "-");
 
}
 /*else if(clicked == jbtnEnter)
 {
 //cStack.push(numbers[0]);
 jtfMain.setText(jtfMain.getText() + " ");
 }*/
 else if(clicked == jbtnEqual)
 {
 jtfMain.setText(jtfMain.getText() + cStack.pop());
 }
 }
 }
 
public static void main(String[] args) {
 Ahsan main = new Ahsan();
 }
 }

Nothing? It throws 'java.util.EmptyStackException' every time I press it. ;)

Probably has something to do with the fact that the 'enterHandler' class is not used anywhere.

Once you deal with that, I have to question why you're doing 'if (cStack.pop().equals("+")) {'. Most RPN calculators only put numbers on the stack. (Putting operators on a stack makes sense for algebraic calculators implementing order of operators and parenthesis.)

You might want to consider making it a 'Stack<BigInteger>'.

Have you ever used an RPN calculator? It might help to try one online, to see how they work. Then you'll have a better idea of what you should be trying to accomplish. Here are two example RPN online calculators: http://www.educalc.net/143111.page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.