Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package mycalculator;
  7.  
  8. import com.jfoenix.controls.JFXButton;
  9. import java.net.URL;
  10. import java.util.ResourceBundle;
  11. import javafx.event.ActionEvent;
  12. import javafx.fxml.FXML;
  13. import javafx.fxml.Initializable;
  14. import javafx.scene.control.TextField;
  15.  
  16. /**
  17. *
  18. * @author KAYES
  19. */
  20. public class DocumentController implements Initializable {
  21. double data =0f;
  22. int operation = -1;
  23. double array[]=new double[2];
  24.  
  25. @FXML
  26. private TextField display;
  27. @FXML
  28. private JFXButton nine;
  29.  
  30. @FXML
  31. private JFXButton minus;
  32.  
  33. @FXML
  34. private JFXButton six;
  35.  
  36. @FXML
  37. private JFXButton mult;
  38.  
  39. @FXML
  40. private JFXButton one;
  41.  
  42. @FXML
  43. private JFXButton clear;
  44.  
  45. @FXML
  46. private JFXButton seven;
  47.  
  48. @FXML
  49. private JFXButton three;
  50.  
  51. @FXML
  52. private JFXButton two;
  53.  
  54. @FXML
  55. private JFXButton dlt;
  56.  
  57. @FXML
  58. private JFXButton plus;
  59.  
  60. @FXML
  61. private JFXButton point;
  62.  
  63. @FXML
  64. private JFXButton eight;
  65.  
  66. @FXML
  67. private JFXButton zero;
  68.  
  69. @FXML
  70. private JFXButton equal;
  71.  
  72. @FXML
  73. private JFXButton div;
  74.  
  75. @FXML
  76. private JFXButton four;
  77.  
  78. @FXML
  79. private JFXButton five;
  80.  
  81. @FXML
  82. private JFXButton log;
  83.  
  84. @FXML
  85. private JFXButton ln;
  86.  
  87. @FXML
  88. private JFXButton sin;
  89.  
  90. @FXML
  91. private JFXButton cos;
  92.  
  93. @FXML
  94. private JFXButton tan;
  95.  
  96. @FXML
  97. private JFXButton pow;
  98.  
  99. @FXML
  100. private JFXButton root;
  101.  
  102. @FXML
  103. private JFXButton fatorial;
  104.  
  105. @FXML
  106. private JFXButton inverse;
  107.  
  108. @FXML
  109. private JFXButton pi;
  110.  
  111.  
  112. /* @FXML
  113. void 849ce4(ActionEvent event) {
  114.  
  115. }*/
  116.  
  117. /* @FXML
  118. void ff0505(ActionEvent event) {
  119.  
  120. }*/
  121.  
  122. @FXML
  123. void handleButtonAction(ActionEvent event) {
  124. if(event.getSource() == one)
  125. {
  126.  
  127. display.setText(display.getText() + "1");
  128. }else if(event.getSource() == two)
  129. {
  130. display.setText(display.getText() + "2");
  131. }else if(event.getSource() == three)
  132. {
  133. display.setText(display.getText() + "3");
  134. }else if(event.getSource() == four)
  135. {
  136. display.setText(display.getText() + "4");
  137. }else if(event.getSource() == five)
  138. {
  139. display.setText(display.getText() + "5");
  140. }else if(event.getSource() == six)
  141. {
  142. display.setText(display.getText() + "6");
  143. }else if(event.getSource() == seven)
  144. {
  145. display.setText(display.getText() + "7");
  146. }else if(event.getSource() == eight)
  147. {
  148. display.setText(display.getText() + "8");
  149. }else if(event.getSource() == nine)
  150. {
  151. display.setText(display.getText() + "9");
  152. }else if(event.getSource() == zero)
  153. {
  154. display.setText(display.getText() + "0");
  155. }else if(event.getSource() == point)
  156. {
  157. display.setText(display.getText() + ".");
  158. } else if(event.getSource() == clear)
  159. {
  160. display.setText("");
  161. }else if(event.getSource() == plus)
  162. {
  163. data = Double.parseDouble(display.getText());
  164. operation =1;
  165. display.setText("");
  166. }else if(event.getSource() == minus)
  167. {
  168. data =Double.parseDouble(display.getText());
  169. operation =2;
  170. display.setText("");
  171. }else if(event.getSource() == mult)
  172. {
  173. data = Float.parseFloat(display.getText());
  174. operation =3;
  175. display.setText("");
  176. }else if(event.getSource() == div)
  177. {
  178. data = Double.parseDouble(display.getText());
  179. operation =4;
  180. display.setText("");
  181.  
  182. }else if(event.getSource() == sin)
  183. {
  184.  
  185. operation =5;
  186. display.setText("sin");
  187.  
  188.  
  189. }
  190. else if(event.getSource() == equal){
  191. Double secondOperand = Double.parseDouble(display.getText());
  192. switch(operation)
  193. {
  194. case 1:
  195. double ans = data + secondOperand;
  196. display.setText(String.valueOf(ans));
  197. array[0]=ans;
  198. break;
  199. case 2:
  200. ans = data - secondOperand;
  201. display.setText(String.valueOf(ans));
  202. array[0]=ans;
  203. break;
  204. case 3:
  205. ans = data * secondOperand;
  206. display.setText(String.valueOf(ans));
  207. array[0]=ans;
  208. break;
  209. case 4:
  210. // double ans = 0;
  211. if(secondOperand ==0 ){
  212. display.setText("\u221E");
  213. }
  214. else{
  215. ans = data /secondOperand;
  216. display.setText(String.valueOf(ans));
  217. array[0]=ans;
  218. }
  219. /* try{
  220. ans =data /secondOperand;
  221. }catch(Exception e){
  222. display.setText("Infinity");
  223. }*/
  224. break;
  225. case 5:
  226.  
  227. data = Double.parseDouble(display.getText());
  228. ans = Math.sin(data);
  229. display.setText(String.valueOf(1/ans));
  230. array[0]=ans;
  231. break;
  232. }
  233. }
  234. }
  235.  
  236. @Override
  237. public void initialize(URL url, ResourceBundle rb) {
  238. // TODO
  239. }
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement