Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package mycalculator;
- import com.jfoenix.controls.JFXButton;
- import java.net.URL;
- import java.util.ResourceBundle;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.TextField;
- /**
- *
- * @author KAYES
- */
- public class DocumentController implements Initializable {
- double data =0f;
- int operation = -1;
- double array[]=new double[2];
- @FXML
- private TextField display;
- @FXML
- private JFXButton nine;
- @FXML
- private JFXButton minus;
- @FXML
- private JFXButton six;
- @FXML
- private JFXButton mult;
- @FXML
- private JFXButton one;
- @FXML
- private JFXButton clear;
- @FXML
- private JFXButton seven;
- @FXML
- private JFXButton three;
- @FXML
- private JFXButton two;
- @FXML
- private JFXButton dlt;
- @FXML
- private JFXButton plus;
- @FXML
- private JFXButton point;
- @FXML
- private JFXButton eight;
- @FXML
- private JFXButton zero;
- @FXML
- private JFXButton equal;
- @FXML
- private JFXButton div;
- @FXML
- private JFXButton four;
- @FXML
- private JFXButton five;
- @FXML
- private JFXButton log;
- @FXML
- private JFXButton ln;
- @FXML
- private JFXButton sin;
- @FXML
- private JFXButton cos;
- @FXML
- private JFXButton tan;
- @FXML
- private JFXButton pow;
- @FXML
- private JFXButton root;
- @FXML
- private JFXButton fatorial;
- @FXML
- private JFXButton inverse;
- @FXML
- private JFXButton pi;
- /* @FXML
- void 849ce4(ActionEvent event) {
- }*/
- /* @FXML
- void ff0505(ActionEvent event) {
- }*/
- @FXML
- void handleButtonAction(ActionEvent event) {
- if(event.getSource() == one)
- {
- display.setText(display.getText() + "1");
- }else if(event.getSource() == two)
- {
- display.setText(display.getText() + "2");
- }else if(event.getSource() == three)
- {
- display.setText(display.getText() + "3");
- }else if(event.getSource() == four)
- {
- display.setText(display.getText() + "4");
- }else if(event.getSource() == five)
- {
- display.setText(display.getText() + "5");
- }else if(event.getSource() == six)
- {
- display.setText(display.getText() + "6");
- }else if(event.getSource() == seven)
- {
- display.setText(display.getText() + "7");
- }else if(event.getSource() == eight)
- {
- display.setText(display.getText() + "8");
- }else if(event.getSource() == nine)
- {
- display.setText(display.getText() + "9");
- }else if(event.getSource() == zero)
- {
- display.setText(display.getText() + "0");
- }else if(event.getSource() == point)
- {
- display.setText(display.getText() + ".");
- } else if(event.getSource() == clear)
- {
- display.setText("");
- }else if(event.getSource() == plus)
- {
- data = Double.parseDouble(display.getText());
- operation =1;
- display.setText("");
- }else if(event.getSource() == minus)
- {
- data =Double.parseDouble(display.getText());
- operation =2;
- display.setText("");
- }else if(event.getSource() == mult)
- {
- data = Float.parseFloat(display.getText());
- operation =3;
- display.setText("");
- }else if(event.getSource() == div)
- {
- data = Double.parseDouble(display.getText());
- operation =4;
- display.setText("");
- }else if(event.getSource() == sin)
- {
- operation =5;
- display.setText("sin");
- }
- else if(event.getSource() == equal){
- Double secondOperand = Double.parseDouble(display.getText());
- switch(operation)
- {
- case 1:
- double ans = data + secondOperand;
- display.setText(String.valueOf(ans));
- array[0]=ans;
- break;
- case 2:
- ans = data - secondOperand;
- display.setText(String.valueOf(ans));
- array[0]=ans;
- break;
- case 3:
- ans = data * secondOperand;
- display.setText(String.valueOf(ans));
- array[0]=ans;
- break;
- case 4:
- // double ans = 0;
- if(secondOperand ==0 ){
- display.setText("\u221E");
- }
- else{
- ans = data /secondOperand;
- display.setText(String.valueOf(ans));
- array[0]=ans;
- }
- /* try{
- ans =data /secondOperand;
- }catch(Exception e){
- display.setText("Infinity");
- }*/
- break;
- case 5:
- data = Double.parseDouble(display.getText());
- ans = Math.sin(data);
- display.setText(String.valueOf(1/ans));
- array[0]=ans;
- break;
- }
- }
- }
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- // TODO
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement