-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.java
42 lines (36 loc) · 1.03 KB
/
Controller.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package application;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.text.Text;
public class Controller {
private String operator = "";
// private String x = "";
private String temp="";
private Operand op1=new Operand();
//private Operand op2=new Operand();
private Model model = new Model();
@FXML
private Text result;
@FXML
private void operand(ActionEvent event) {
result.setText(result.getText() + ((Button)event.getSource()).getText());
}
@FXML
private void operator(ActionEvent event) {
if(((Button) event.getSource()).getText().equals("=")) {
// op2.reverse(result.getText());
temp=(String)(result.getText());
String reversed="";
for(int i=temp.length()-1;i>=0;i--){
reversed+=String.valueOf(temp.charAt(i));
}
result.setText(model.calculate(operator, op1, reversed));
} else {
operator = ((Button)event.getSource()).getText();
temp = result.getText();
op1.reverse(temp);
result.setText("");
}
}
}