├── .DS_Store
├── image
└── calculator_image.png
├── target
└── classes
│ ├── module-info.class
│ └── com
│ └── example
│ └── javafxcalculator
│ ├── Formula
│ └── Formula.class
│ ├── HelloApplication.class
│ ├── HelloController.class
│ └── hello-view.fxml
├── .idea
├── vcs.xml
├── .gitignore
├── encodings.xml
├── modules.xml
├── misc.xml
├── libraries
│ ├── Maven__org_opentest4j_opentest4j_1_2_0.xml
│ ├── Maven__org_controlsfx_controlsfx_11_1_0.xml
│ ├── Maven__org_openjfx_javafx_base_18_ea_6.xml
│ ├── Maven__org_openjfx_javafx_fxml_18_ea_6.xml
│ ├── Maven__org_openjfx_javafx_controls_18_ea_6.xml
│ ├── Maven__org_openjfx_javafx_graphics_18_ea_6.xml
│ ├── Maven__org_apiguardian_apiguardian_api_1_1_2.xml
│ ├── Maven__org_openjfx_javafx_base_mac_aarch64_18_ea_6.xml
│ ├── Maven__org_openjfx_javafx_fxml_mac_aarch64_18_ea_6.xml
│ ├── Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml
│ ├── Maven__org_openjfx_javafx_controls_mac_aarch64_18_ea_6.xml
│ ├── Maven__org_openjfx_javafx_graphics_mac_aarch64_18_ea_6.xml
│ ├── Maven__org_kordamp_bootstrapfx_bootstrapfx_core_0_4_0.xml
│ ├── Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml
│ ├── Maven__org_junit_platform_junit_platform_engine_1_8_1.xml
│ └── Maven__org_junit_platform_junit_platform_commons_1_8_1.xml
├── jarRepositories.xml
└── compiler.xml
├── README.md
├── src
└── main
│ ├── java
│ ├── module-info.java
│ └── com
│ │ └── example
│ │ └── javafxcalculator
│ │ ├── HelloController.java
│ │ ├── HelloApplication.java
│ │ └── Formula
│ │ └── Formula.java
│ └── resources
│ └── com
│ └── example
│ └── javafxcalculator
│ └── hello-view.fxml
├── JavaFX-Calculator.iml
└── pom.xml
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/.DS_Store
--------------------------------------------------------------------------------
/image/calculator_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/image/calculator_image.png
--------------------------------------------------------------------------------
/target/classes/module-info.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/target/classes/module-info.class
--------------------------------------------------------------------------------
/target/classes/com/example/javafxcalculator/Formula/Formula.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/target/classes/com/example/javafxcalculator/Formula/Formula.class
--------------------------------------------------------------------------------
/target/classes/com/example/javafxcalculator/HelloApplication.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/target/classes/com/example/javafxcalculator/HelloApplication.class
--------------------------------------------------------------------------------
/target/classes/com/example/javafxcalculator/HelloController.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PersesTitan/JavaFX-Calculator/HEAD/target/classes/com/example/javafxcalculator/HelloController.class
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JavaFX-Calculator
2 | 계산기 GUI 연습 프로잭트입니다.
3 |
4 | 동작 이미지
5 | 
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/main/java/module-info.java:
--------------------------------------------------------------------------------
1 | module com.example.javafxcalculator {
2 | requires javafx.controls;
3 | requires javafx.fxml;
4 |
5 | requires org.controlsfx.controls;
6 | requires org.kordamp.bootstrapfx.core;
7 |
8 | opens com.example.javafxcalculator to javafx.fxml;
9 | exports com.example.javafxcalculator;
10 | }
--------------------------------------------------------------------------------
/src/main/java/com/example/javafxcalculator/HelloController.java:
--------------------------------------------------------------------------------
1 | package com.example.javafxcalculator;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.Label;
5 |
6 | public class HelloController {
7 | @FXML
8 | private Label welcomeText;
9 |
10 | @FXML
11 | protected void onHelloButtonClick() {
12 | welcomeText.setText("계산기 출력");
13 | }
14 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_opentest4j_opentest4j_1_2_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_controlsfx_controlsfx_11_1_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_base_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_fxml_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/main/resources/com/example/javafxcalculator/hello-view.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/target/classes/com/example/javafxcalculator/hello-view.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_controls_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_graphics_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_1_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_base_mac_aarch64_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_fxml_mac_aarch64_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_controls_mac_aarch64_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_openjfx_javafx_graphics_mac_aarch64_18_ea_6.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_kordamp_bootstrapfx_bootstrapfx_core_0_4_0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_engine_5_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_junit_platform_junit_platform_engine_1_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_8_1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/main/java/com/example/javafxcalculator/HelloApplication.java:
--------------------------------------------------------------------------------
1 | package com.example.javafxcalculator;
2 |
3 | import javafx.application.Application;
4 | import javafx.event.ActionEvent;
5 | import javafx.event.EventHandler;
6 | import javafx.geometry.Insets;
7 | import javafx.scene.Scene;
8 | import javafx.scene.control.Button;
9 | import javafx.scene.control.Label;
10 | import javafx.scene.layout.HBox;
11 | import javafx.scene.layout.VBox;
12 | import javafx.scene.text.Font;
13 | import javafx.stage.Stage;
14 |
15 | import static com.example.javafxcalculator.Formula.Formula.formula;
16 |
17 | public class HelloApplication extends Application implements EventHandler {
18 |
19 | Label label;
20 | Button[] buttons;
21 | String TotalText = "";
22 | Stage stage;
23 | VBox vBox = new VBox();
24 | HBox hBox = new HBox();
25 | HBox hBox1 = new HBox();
26 | HBox hBox2 = new HBox();
27 | HBox hBox3 = new HBox();
28 | HBox hBox4 = new HBox();
29 | HBox hBox5 = new HBox();
30 | HBox[] hBoxS = {hBox1, hBox2, hBox3, hBox4, hBox5};
31 |
32 | @Override
33 | public void start(Stage stage) {
34 | this.stage = stage;
35 | buttons = new Button[17];
36 | final String[] texts = {
37 | "OFF", "AC", "/", "*",
38 | "1", "2", "3", "-",
39 | "4", "5", "6", "+",
40 | "7", "8", "9", "=",
41 | "0"};
42 |
43 | stage.setTitle("Calculator");
44 |
45 | hBox.setPadding(new Insets(10));
46 | hBox.setSpacing(10);
47 |
48 | label = new Label();
49 | label.setFont(new Font("Arial", 30));
50 | vBox.getChildren().add(label);
51 |
52 | for (int i = 0; i clickButton(act.getSource()));
67 | }
68 | }
69 |
70 | public static void main(String[] args) {
71 | launch();
72 | }
73 |
74 | private void clickButton(Object button) {
75 | Button btn = (Button) button;
76 | String buttonText = btn.getText();
77 |
78 | switch (buttonText) {
79 | case "OFF" -> stage.close();
80 | case "AC" -> TotalText = "";
81 | case "=" -> TotalText = Double.toString(formula(TotalText, true));
82 | default -> TotalText += buttonText;
83 | }
84 | label.setText(TotalText);
85 | }
86 | }
--------------------------------------------------------------------------------
/JavaFX-Calculator.iml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | JavaFX-Calculator
9 | 1.0-SNAPSHOT
10 | JavaFX-Calculator
11 |
12 |
13 | UTF-8
14 | 5.8.1
15 |
16 |
17 |
18 |
19 | org.openjfx
20 | javafx-controls
21 | 18-ea+6
22 |
23 |
24 | org.openjfx
25 | javafx-fxml
26 | 18-ea+6
27 |
28 |
29 | org.controlsfx
30 | controlsfx
31 | 11.1.0
32 |
33 |
34 | org.kordamp.bootstrapfx
35 | bootstrapfx-core
36 | 0.4.0
37 |
38 |
39 | org.junit.jupiter
40 | junit-jupiter-api
41 | ${junit.version}
42 | test
43 |
44 |
45 | org.junit.jupiter
46 | junit-jupiter-engine
47 | ${junit.version}
48 | test
49 |
50 |
51 |
52 |
53 |
54 |
55 | org.apache.maven.plugins
56 | maven-compiler-plugin
57 | 3.8.1
58 |
59 | 18
60 | 18
61 |
62 |
63 |
64 | org.openjfx
65 | javafx-maven-plugin
66 | 0.0.8
67 |
68 |
69 |
70 | default-cli
71 |
72 | com.example.javafxcalculator/com.example.javafxcalculator.HelloApplication
73 |
74 | app
75 | app
76 | app
77 | true
78 | true
79 | true
80 |
81 |
82 |
83 |
84 |
85 |
86 |
--------------------------------------------------------------------------------
/src/main/java/com/example/javafxcalculator/Formula/Formula.java:
--------------------------------------------------------------------------------
1 | package com.example.javafxcalculator.Formula;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Arrays;
5 | import java.util.Collections;
6 | import java.util.List;
7 |
8 | public class Formula {
9 |
10 | public String plus = "+";
11 | public String multiple = "*";
12 | public String minus = "-";
13 | public String division = "/";
14 | static Formula formula = new Formula();
15 |
16 | public static void formula(String plus, String minus, String multiple, String division) {
17 | formula.plus = plus;
18 | formula.minus = minus;
19 | formula.multiple = multiple;
20 | formula.division = division;
21 | }
22 |
23 | //괄호 연산하는 메소드
24 | public static double formula(String line, boolean operation) {
25 | if (count(line, ')') != count(line, '('))
26 | System.err.println("괄호의 짝이 일치하지 않습니다.");
27 |
28 | int firstPosition = line.lastIndexOf("(");
29 | int secondPosition = line.indexOf(")")+1;
30 |
31 | while(check(line)) {
32 | String Line = line.substring(firstPosition, secondPosition);
33 | String inLine = line.substring(firstPosition+1, secondPosition-1);
34 | String outLine = String.valueOf(form(inLine, operation));
35 | line = line.replace(Line, outLine);
36 | }
37 |
38 | line = String.valueOf(form(line, operation));
39 | return Double.parseDouble(line);
40 | }
41 |
42 | private static double form(String lines, boolean operation) {
43 | String multiple;
44 | String plus;
45 | if (formula.multiple.equals("*")) multiple = "\\*";
46 | else multiple = formula.multiple;
47 |
48 | if (formula.plus.equals("+")) plus = "\\+";
49 | else plus = formula.plus;
50 |
51 | String minus = formula.minus;
52 | String division = formula.division;
53 |
54 | lines = lines.replace(" ", "");
55 | lines = lines.replace(minus, " "+minus);
56 | String[] numbers = lines.split(plus+"|"+multiple+"|"+division+"|"+" ");
57 | String[] sings = lines.replace(minus, formula.plus).split("[0-9|^.]");
58 | multiple = formula.multiple;
59 |
60 | List numberList = new ArrayList<>(Arrays.asList(numbers));
61 | List singList = new ArrayList<>(Arrays.asList(sings));
62 | numberList.removeAll(Collections.singletonList(""));
63 | numberList.removeAll(Collections.singletonList(null));
64 | singList.removeAll(Collections.singletonList(""));
65 | singList.removeAll(Collections.singletonList(null));
66 | assert numbers.length == sings.length+1;
67 |
68 | //디버깅용
69 | // System.out.println(numberList);
70 | // System.out.println(singList);
71 |
72 | while (singList.size()>0) {
73 | if (operation) {
74 | if (formula.check(singList) && singList.size()>1) {
75 | int position = (int) formula.count(singList);
76 | double totalNumber = Double.parseDouble(numberList.get(position));
77 |
78 | String sing = singList.get(position);
79 |
80 | if (multiple.equals(sing)) totalNumber *= Double.parseDouble(numberList.get(position+1));
81 | else if (division.equals(sing)) totalNumber /= Double.parseDouble(numberList.get(position+1));
82 | else System.err.println("예기치 못한 에러가 발생하였습니다. - Formula");
83 |
84 | numberList.set(position, Double.toString(totalNumber));
85 | numberList.remove(position+1);
86 | singList.remove(position);
87 |
88 | } else calculation(numberList, singList);
89 | } else calculation(numberList, singList);
90 | }
91 | return Double.parseDouble(numberList.get(0));
92 | }
93 |
94 | /**
95 | * @param numberList 숫자를 저장하는 리스트
96 | * @param singList 기호를 저장하는 리스트
97 | */
98 |
99 | private static void calculation(List numberList, List singList) {
100 | double total = Double.parseDouble(numberList.get(0));
101 | for (int i = 0; i list) {
129 | return list.contains(multiple) || list.contains(division);
130 | }
131 |
132 | public long count(List list) {
133 | return list.stream().filter(s -> s.equals(multiple)||s.equals(division)).count();
134 | }
135 |
136 | private static boolean check(String line) {
137 | return line.contains(")") || line.contains("(");
138 | }
139 |
140 | private static long count(String line, char c) {
141 | return line.chars().filter(ch -> ch==c).count();
142 | }
143 | }
--------------------------------------------------------------------------------