0 Star 0 Fork 0

Mousou / java201521123018

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
README.md 2.32 KB
Copy Edit Raw Blame History
Mousou authored 2017-06-24 01:20 . 更新 README.md
private class OperationMouseListener implements MouseListener{

	public void mouseClicked(MouseEvent e) {
		if(e.getSource() == backspace){//退格键,删除一个直到没有字符删除
			String inputText = input.getText();
			if(inputText.length() > 0){
				input.setText(inputText.substring(0, inputText.length() - 1));
			}
		}else if(e.getSource() == neg){
			String text = input.getText().trim();
			 if(text.contains("-")){  
				 input.setText(text.substring(1,text.length()));  
		        }else{  
		        	input.setText( "-" + text);  
		        } 
		}
		else if(e.getSource() == C){
			input.setText("0");//C,清空所有运算数字和符号
			num1 = "";
		}else if(e.getSource() == CE){
			input.setText("0");//CE-->将文本框置为0
		}else if(e.getSource() == decimal){
			String text = input.getText().trim();
			//如果按了小数点,如果文本框已经有小数点,不做任何操作,否则在结果后面加上小数点
			if(text.indexOf(".") == -1){
				input.setText(text.concat("."));
			}
		}else if(e.getSource() == equal){
			//如果是等号
			if(!operator.trim().equals("")){
				if(!input.getText().trim().equals("")){
					double result = 0D;
					if(operator.equals("+")){//执行加法运算
						result = Double.parseDouble(num1) + Double.parseDouble(input.getText().trim().substring(input.getText().trim().indexOf("+") + 1));
					}else if(operator.equals("-")){//减法运算
						result = Double.parseDouble(num1) - Double.parseDouble(input.getText().trim().substring(input.getText().trim().indexOf("-") + 1));
					}else if(operator.equals("*")){//乘法运算
						result = Double.parseDouble(num1) * Double.parseDouble(input.getText().trim().substring(input.getText().trim().indexOf("*") + 1));
					}else if(operator.equals("/")){//除法运算
						result = Double.parseDouble(num1) / Double.parseDouble(input.getText().trim().substring(input.getText().trim().indexOf("/") + 1));
					}
					 //格式化最终结果,保留两位小数点
					input.setText(new DecimalFormat("0.00").format(result));
				}
			}
		}
		
	}

	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}	
}
Java
1
https://gitee.com/Yuan_J/java201521123018.git
git@gitee.com:Yuan_J/java201521123018.git
Yuan_J
java201521123018
java201521123018
课设

Search

53164aa7 5694891 3bd8fe86 5694891