Monday, December 2, 2013

calculator
































im working for a calculator using eclipse. for the "=" button ive written the code:































JButton btn_result = new JButton("=");































btn_result.addActionListener(new ActionListener() {































public void actionPerformed(ActionEvent e) {































secondDouble=(Double.parseDouble(String.valueOf(di splay.getText())));































if(plusClick>0){































totalDouble=firstDouble+secondDouble;































display.setText(String.valueOf(totalDouble));































firstDouble=0;































secondDouble=0;































plusClick=0;
































}































if(minusClick>0){































totalDouble=firstDouble-secondDouble;































display.setText(String.valueOf(totalDouble));































firstDouble=0;































secondDouble=0;































minusClick=0;
































}































if(multiplyClick>0){































totalDouble=firstDouble*secondDouble;































display.setText(String.valueOf(totalDouble));































firstDouble=0;































secondDouble=0;































multiplyClick=0;
































}































if(divideClick>0){































totalDouble=firstDouble/secondDouble;































display.setText(String.valueOf(totalDouble));































firstDouble=0;































secondDouble=0;































divideClick=0;































}































if(percentageClick>0){































totalDouble=(firstDouble * 100/ secondDouble);































display.setText(String.valueOf(totalDouble));































firstDouble=0;































secondDouble=0;































percentageClick=0;































}































System.out.println("In ActionPerformed");































the problem is: i want to repeat this action for any click of the "=" ... ex. 8-3 click=, result 5. now i click again= and i wont the result 2. like the microsoft calculator... help pleaasee :)































































No comments:

Post a Comment