import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class gdfsf extends Application {
TextField ekran = new TextField("");
Button b0 = new Button("0");Button b1 = new Button("1");Button b2 = new Button("2");Button b3 = new Button("3");Button b4 = new Button("4");
Button b5 = new Button("5");Button b6 = new Button("6");Button b7 = new Button("7");Button b8 = new Button("8");Button b9 = new Button("9");
Button üçSıfır = new Button("000");Button e = new Button("e");Button pi = new Button("\u03C0");Button nokta = new Button(".");
Button topla = new Button("+");Button çıkar = new Button("-");Button çarp = new Button("x");Button böl = new Button("/");Button mod = new Button("%");
Button artı_eksi = new Button("+/-");Button kök = new Button("%");Button sqr = new Button("\u221A" + "x");Button reverse = new Button("1/x");
Button sin = new Button("sin");Button cos = new Button("cos");Button tan = new Button("tan");Button cot = new Button("cot");
Button sinh = new Button("sinh");Button cosh = new Button("cosh");Button tanh = new Button("tanh");Button coth = new Button("coth");
Button asin = new Button("aSin");Button acos = new Button("aCos");Button atan = new Button("aTan");Button acot = new Button("aCot");
Button log = new Button("log");Button ln = new Button("ln");Button exp = new Button("exp");Button x_over_y = new Button("x^y");
Button factorial = new Button("x!");Button eşittir = new Button("=");Button AC = new Button("AC");Button del = new Button("DEL");
double currentNumber;String operation;
@Override
public void start(Stage m) {
b0.setPrefSize(45, 45);b1.setPrefSize(45, 45);b2.setPrefSize(45, 45);b3.setPrefSize(45, 45);b4.setPrefSize(45, 45);b5.setPrefSize(45, 45);
b6.setPrefSize(45, 45);b7.setPrefSize(45, 45);b8.setPrefSize(45, 45);b9.setPrefSize(45, 45);üçSıfır.setPrefSize(45, 45);
e.setPrefSize(45, 45);pi.setPrefSize(45, 45);nokta.setPrefSize(45, 45);eşittir.setPrefSize(45, 45);topla.setPrefSize(45, 45);
çıkar.setPrefSize(45, 45);çarp.setPrefSize(45, 45);böl.setPrefSize(45, 45);sqr.setPrefSize(45, 45);mod.setPrefSize(45, 45);
artı_eksi.setPrefSize(45, 45);sin.setPrefSize(45, 45);cos.setPrefSize(45, 45);tan.setPrefSize(45, 45);cot.setPrefSize(45, 45);
asin.setPrefSize(45, 45);acos.setPrefSize(45, 45);atan.setPrefSize(45, 45);acot.setPrefSize(45, 45);sinh.setPrefSize(45, 45);
cosh.setPrefSize(45, 45);tanh.setPrefSize(45, 45);coth.setPrefSize(45, 45);log.setPrefSize(45, 45);ln.setPrefSize(45, 45);
exp.setPrefSize(45, 45);x_over_y.setPrefSize(45, 45);factorial.setPrefSize(45, 45);AC.setPrefSize(45, 45);del.setPrefSize(45, 45);
reverse.setPrefSize(45, 45);ekran.setPrefHeight(42);ekran.setAlignment(Pos.CENTER_RIGHT);
ekran.setStyle("-fx-background-color:ghostwhite;");
b0.setStyle("-fx-background-color:lightyellow;");b0.setOnAction(e -> handleDigitAction(e));
b1.setStyle("-fx-background-color:lightyellow;");b1.setOnAction(e -> handleDigitAction(e));
b2.setStyle("-fx-background-color:yellow;");b2.setOnAction(e -> handleDigitAction(e));
b3.setStyle("-fx-background-color:gold;");b3.setOnAction(e -> handleDigitAction(e));
b4.setStyle("-fx-background-color:yellow;");b4.setOnAction(e -> handleDigitAction(e));
b5.setStyle("-fx-background-color:yellow;");b5.setOnAction(e -> handleDigitAction(e));
b6.setStyle("-fx-background-color:gold;");b6.setOnAction(e -> handleDigitAction(e));
b7.setStyle("-fx-background-color:gold;");b7.setOnAction(e -> handleDigitAction(e));
b8.setStyle("-fx-background-color:gold;");b8.setOnAction(e -> handleDigitAction(e));
b9.setStyle("-fx-background-color:gold;");b9.setOnAction(e -> handleDigitAction(e));
üçSıfır.setStyle("-fx-background-color:yellow;");üçSıfır.setOnAction(e -> handleDigitAction(e));
nokta.setStyle("-fx-background-color:gold;");nokta.setOnAction(e -> handleDigitAction(e));
e.setStyle("-fx-background-color:darkorange;");e.setOnAction(e -> handleDigitAction(e));
pi.setStyle("-fx-background-color:darkorange;");pi.setOnAction(e -> handleDigitAction(e));
topla.setStyle("-fx-background-color:orange;");topla.setOnAction(e -> handleOperation(e));
çıkar.setStyle("-fx-background-color:orange;");çıkar.setOnAction(e -> handleOperation(e));
çarp.setStyle("-fx-background-color:orange;");çarp.setOnAction(e -> handleOperation(e));
böl.setStyle("-fx-background-color:orange;");böl.setOnAction(e -> handleOperation(e));
x_over_y.setStyle("-fx-background-color:red;");x_over_y.setOnAction(e -> handleOperation(e));
mod.setStyle("-fx-background-color:red;");mod.setOnAction(e -> handleOperation(e));
sin.setStyle("-fx-background-color:darkorange;");sin.setOnAction(e -> handleTrigonometricAction(e));
cos.setStyle("-fx-background-color:darkorange;");cos.setOnAction(e -> handleTrigonometricAction(e));
tan.setStyle("-fx-background-color:darkorange;");tan.setOnAction(e -> handleTrigonometricAction(e));
cot.setStyle("-fx-background-color:darkorange;");cot.setOnAction(e -> handleTrigonometricAction(e));
sinh.setStyle("-fx-background-color:darkorange;");sinh.setOnAction(e -> handleTrigonometricAction(e));
cosh.setStyle("-fx-background-color:darkorange;");cosh.setOnAction(e -> handleTrigonometricAction(e));
tanh.setStyle("-fx-background-color:darkorange;");tanh.setOnAction(e -> handleTrigonometricAction(e));
coth.setStyle("-fx-background-color:darkorange;");coth.setOnAction(e -> handleTrigonometricAction(e));
asin.setStyle("-fx-background-color:red;");asin.setOnAction(e -> handleTrigonometricAction(e));
acos.setStyle("-fx-background-color:red;");acos.setOnAction(e -> handleTrigonometricAction(e));
atan.setStyle("-fx-background-color:red;");atan.setOnAction(e -> handleTrigonometricAction(e));
acot.setStyle("-fx-background-color:red;");acot.setOnAction(e -> handleTrigonometricAction(e));
artı_eksi.setStyle("-fx-background-color:orange;");artı_eksi.setOnAction(e -> negative_positiveAction(e));
log.setStyle("-fx-background-color:red;");log.setOnAction(e -> otherCalculationsAction(e));
ln.setStyle("-fx-background-color:red;");ln.setOnAction(e -> otherCalculationsAction(e));
sqr.setStyle("-fx-background-color:red;");sqr.setOnAction(e -> otherCalculationsAction(e));
reverse.setStyle("-fx-background-color:red;");reverse.setOnAction(e -> otherCalculationsAction(e));
exp.setStyle("-fx-background-color:red;");exp.setOnAction(e -> otherCalculationsAction(e));
factorial.setStyle("-fx-background-color:red;");factorial.setOnAction(e -> otherCalculationsAction(e));
eşittir.setStyle("-fx-background-color:orange;");eşittir.setOnAction(e -> handleEqualAction(e));
AC.setStyle("-fx-background-color:orange;");AC.setOnAction(e -> handleClearEvent(e));
del.setStyle("-fx-background-color:orange;");del.setOnAction(e -> handleDeleteEvent(e));
GridPane pane = new GridPane();
pane.addColumn(0, log, sin, AC, b7, b4, b1, b0);pane.addColumn(1, ln, cos, del, b8, b5, b2, üçSıfır);pane.addColumn(2, exp, tan, artı_eksi, b9, b6, b3, nokta);
pane.addColumn(3, factorial, cot, böl, çarp, çıkar, topla, eşittir);pane.addColumn(4, x_over_y, sinh, cosh, tanh, coth, e, pi);
pane.addColumn(5, sqr, asin, acos, atan, acot, reverse, mod);pane.setPadding(new Insets(10, 0, 0, 0));
BorderPane b = new BorderPane();
b.setTop(ekran);b.setBottom(pane);b.setPadding(new Insets(10, 10, 10, 10));b.setStyle("-fx-background-color:slategray;");
Scene s = new Scene(b);m.setScene(s);m.setTitle("MY SCIENTIFIC CALCULATOR");m.show();
}
private void handleDigitAction(ActionEvent event) {
String digit = ((Button) event.getSource()).getText();
String oldText = ekran.getText();
String newText = oldText + digit;
if (digit.equals("e")) {
ekran.setText(Double.toString(Math.E));
} else if (digit.equals("\u03C0")) {
ekran.setText(Double.toString(Math.PI));
} else
ekran.setText(newText);
}
private void handleEqualAction(ActionEvent event) {
String newText = ekran.getText();
double newNumber = Double.parseDouble(newText);
switch (operation) {
case "+":currentNumber = currentNumber + newNumber;break;
case "-":currentNumber = currentNumber - newNumber;break;
case "x":currentNumber = currentNumber * newNumber;break;
case "/":currentNumber = currentNumber / newNumber;break;
case "%":currentNumber = currentNumber % newNumber;break;
case "x^y": currentNumber = Math.pow(currentNumber, newNumber);break;
default:break;}
ekran.setText("" + currentNumber);}
private void handleOperation(ActionEvent event) {
String currentText = ekran.getText();currentNumber = Double.parseDouble(currentText);
ekran.setText("");operation = ((Button) event.getSource()).getText();
}
private void handleDeleteEvent(ActionEvent event) {
String back = ekran.getText()
.substring(0, ekran.getText().length() - 1);
if (back.equals("0") || back.length() == 0)ekran.setText("");
else ekran.setText(back);
}
private void handleClearEvent(ActionEvent event) {
ekran.clear();
}
private void negative_positiveAction(ActionEvent event) {
double number1 = Double.parseDouble(ekran.getText());double number2;
if (number1 < 0) {number2 = number1 * (-1);ekran.setText("" + number2);}
else if (number1 > 0) {number2 = number1 * (-1);ekran.setText("" + number2);}
}
private void handleTrigonometricAction(ActionEvent event) {
String newText = ekran.getText();operation = ((Button) event.getSource()).getText();double newNumber = Double.parseDouble(newText);
switch (operation) {
case "cos":
if (newNumber % 360 == 90 || newNumber % 360 == 270) {ekran.setText("0");break;}
else {currentNumber = Math.cos(Math.toRadians(newNumber));ekran.setText("" + currentNumber);break;}
case "sin":
if (newNumber % 360 == 180 || newNumber % 360 == 0) {ekran.setText("0");break;}
else {currentNumber = Math.sin(Math.toRadians(newNumber));ekran.setText("" + currentNumber);break;}
case "tan":
if (newNumber % 360 == 90 || newNumber % 360 == 270) {ekran.setText("NaN");break;}
else {currentNumber = Math.tan(Math.toRadians(newNumber));ekran.setText("" + currentNumber);break;}
case "cot":
if (newNumber % 360 == 180 || newNumber % 360 == 0) {ekran.setText("NaN");break;}
else {currentNumber = 1 / Math.tan(Math.toRadians(newNumber));ekran.setText("" + currentNumber);break;}
case "sinh":currentNumber = Math.sinh(newNumber);ekran.setText("" + currentNumber);break;
case "cosh":currentNumber = Math.cosh(newNumber);ekran.setText("" + currentNumber);break;
case "tanh":currentNumber = Math.tanh(newNumber);ekran.setText("" + currentNumber);break;
case "coth":currentNumber = 1 / Math.tanh(newNumber);ekran.setText("" + currentNumber);break;
case "aSin":currentNumber = Math.toDegrees(Math.asin(newNumber));ekran.setText("" + currentNumber + " \u00b0");break;
case "aCos":currentNumber = Math.toDegrees(Math.acos(newNumber));ekran.setText("" + currentNumber + " \u00b0");break;
case "aTan":currentNumber = Math.toDegrees(Math.atan(newNumber));ekran.setText("" + currentNumber + " \u00b0");break;
case "aCot":currentNumber = Math.toDegrees(1 / Math.acos(newNumber));ekran.setText("" + currentNumber + " \u00b0");break;
}
}
private void otherCalculationsAction(ActionEvent event) {
String newText = ekran.getText();
operation = ((Button) event.getSource()).getText();
double newNumber = Double.parseDouble(newText);
switch (operation) {
case "log":
if (newNumber <= 0) {ekran.setText("NaN");break;}
else {currentNumber = Math.log10(newNumber);ekran.setText("" + currentNumber);break;}
case "ln":
if (newNumber <= 0) {ekran.setText("NaN");break;
} else {currentNumber = Math.log(newNumber);ekran.setText("" + currentNumber);break;}
case "exp":currentNumber = Math.exp(newNumber);ekran.setText("" + currentNumber);break;
case "x!":currentNumber = factorial(newNumber);ekran.setText("" + currentNumber);break;
case "\u221A" + "x":currentNumber = Math.sqrt(newNumber);ekran.setText("" + currentNumber);break;
case "1/x":currentNumber = 1 / newNumber;ekran.setText("" + currentNumber);break;
}
}
public double factorial(double number) {
if (number == 0)return 1;
else return number * factorial(number - 1);
}
public static void main(String[] args) {
Application.launch(args);
}
}