1 Star 0 Fork 0

java201521123019 / Java课设

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
java201521123019 authored 2017-06-24 00:29 . 更新 README.md

#Java课设

            //注册各个组件监听事件
	backspace.addMouseListener(new OperationMouseListener());
	CE.addMouseListener(new OperationMouseListener());
	C.addMouseListener(new OperationMouseListener());
	decimal.addMouseListener(new OperationMouseListener());
	equal.addMouseListener(new OperationMouseListener());
	neg.addMouseListener(new OperationMouseListener());
	
	//注册四则运算鼠标监听
	add.addMouseListener(new CalcMouseListener());
	sub.addMouseListener(new CalcMouseListener());
	mul.addMouseListener(new CalcMouseListener());
	div.addMouseListener(new CalcMouseListener());
	
	//注册数字监听事件
	zero.addMouseListener(new NumberMouseListener());
	one.addMouseListener(new NumberMouseListener());
	two.addMouseListener(new NumberMouseListener());
	three.addMouseListener(new NumberMouseListener());
	four.addMouseListener(new NumberMouseListener());
	five.addMouseListener(new NumberMouseListener());
	six.addMouseListener(new NumberMouseListener());
	seven.addMouseListener(new NumberMouseListener());
	eight.addMouseListener(new NumberMouseListener());
	nine.addMouseListener(new NumberMouseListener());
			
}

private class NumberMouseListener implements MouseListener{

	public void mouseClicked(MouseEvent e) {
		if(input.getText().trim().equals("0")){//如果文本框已经是0,结果还是0
			input.setText(((JButton)e.getSource()).getText().trim());
		}else{//否则的话,把0添加到后面,譬如文本框是1,结果就为10
			input.setText(input.getText().concat(((JButton)e.getSource()).getText().trim()));
		}
	}

	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {}
	public void mouseReleased(MouseEvent e) {}	
}


private class CalcMouseListener implements MouseListener{
	//如果输入的是运算符号,保存第一个结果和运算符号 
	public void mouseClicked(MouseEvent e) {
		num1 = input.getText().trim();
		input.setText("");
		operator = ((JButton)e.getSource()).getText().trim();
		input.setText(num1+operator);
	}

	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/Umaru/javakeshe.git
git@gitee.com:Umaru/javakeshe.git
Umaru
javakeshe
Java课设
master

Search

53164aa7 5694891 3bd8fe86 5694891