diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000000000000000000000000000000000000..13566b81b018ad684f3a35fee301741b2734c8f4
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f3e0cf121433bc4f924db9528ab79365af78eb13
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000000000000000000000000000000000000..07115cdf15dd408d3affb9240e112578e04abf68
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000000000000000000000000000000000000..f88aa8319569ce34b0a87aab980782499528c45c
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000000000000000000000000000000000000..e96534fb27b68192f27f985d3879e173ec77adb8
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000000000000000000000000000000000000..28e42c3653858c82ca382c7f4e40d21e91f7a5a0
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2022_Spring_0109_calculator.iml b/2022_Spring_0109_calculator.iml
new file mode 100644
index 0000000000000000000000000000000000000000..c90834f2d607afe55e6104d8aa2cdfffb713f688
--- /dev/null
+++ b/2022_Spring_0109_calculator.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/904c00f112f7e8e7e310e60a24830c6.jpg b/904c00f112f7e8e7e310e60a24830c6.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..e653b3b002676e4cfa55506fb29b905d172e01f8
Binary files /dev/null and b/904c00f112f7e8e7e310e60a24830c6.jpg differ
diff --git a/src/AppMain/Main.java b/src/AppMain/Main.java
new file mode 100644
index 0000000000000000000000000000000000000000..dbf14855190bbb0c07b5af5f9a94b27d136df6f7
--- /dev/null
+++ b/src/AppMain/Main.java
@@ -0,0 +1,24 @@
+package AppMain;
+
+import SwingEvents.OptionMouseListener;
+import UI.SimpleCalculatorUI.Win;
+
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+
+/**
+ * @ClassName:Main
+ * @Description:应用入口
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 42
+ * @version:v1.0
+ */
+public class Main {
+ public static Win win;
+
+ public static void main(String[] args) {
+ win = new Win(500, 100, 450, 700);
+ }
+}
diff --git a/src/Function/Function.java b/src/Function/Function.java
new file mode 100644
index 0000000000000000000000000000000000000000..401d4ebc099088dee04085980c5f80a522d1b91c
--- /dev/null
+++ b/src/Function/Function.java
@@ -0,0 +1,50 @@
+package Function;
+
+/**
+ * @ClassName:Function
+ * @Description:加减乘除等各计算方法的集合
+ * @Author:LMD傻蛋
+ * @Date:2022/5/19 00 44
+ * @version:v1.0
+ */
+public class Function {
+ public Function() {
+
+ }
+
+ public double add(double x, double y) {//加
+ return x + y;
+ }
+
+ public double subtract(double x, double y) {
+ return x - y;
+ }//减
+
+ public double multiply(double x, double y) {
+ return x * y;
+ }//乘
+
+ public double divide(double x, double y) {
+ if (y == 0) {
+ System.out.println("被除数不能为0");//被除数为0输出提示,结果置0
+ return 0;
+ }
+ return x / y;
+ }//除
+
+ public double modulo(double x, double y) {//取模
+ return x % y;
+ }
+
+ public double pow(double x, double y) {//求x的y次方
+ return Math.pow(x, y);
+ }
+
+ public double logarithm_e(double x) {//lnx
+ return Math.log(x);
+ }
+
+ public double logarithm_10(double x) {//lgx
+ return Math.log10(x);
+ }
+}
diff --git a/src/SwingEvents/Key_screenListener.java b/src/SwingEvents/Key_screenListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..9bb63fde1845724e1743a5ba417554c7f9b652c3
--- /dev/null
+++ b/src/SwingEvents/Key_screenListener.java
@@ -0,0 +1,493 @@
+package SwingEvents;
+
+import Function.Function;
+import UI.SimpleCalculatorUI.Panel.ScreenPanel;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.math.BigDecimal;
+
+/**
+ * @ClassName:Key_screenListener
+ * @Description:监听键盘与显示屏行为,做出相应反应
+ * @Author:LMD傻蛋
+ * @Date:2022/5/19 00 50
+ * @version:v1.0
+ */
+/*
+1.点击0-9数字,在showTextLow显示
+ 1.1限制显示位数
+2.在数字后跟“+-x/%.”正常显示
+ 2.1无数字时输入“+-”作正负号,其他在初始数字“0”后跟
+3.单击“=”showTextLow显示结果,计算式上移一行。
+4.再输入,结果并入中间行,底行显示新输入
+5.点击“C”,清空所有行内容,底行显示0
+6.点击“Del”,逐字删除底行内容,直到删完置0,但不影响其他行
+ */
+public class Key_screenListener implements ActionListener {
+ JTextField showHigh = ScreenPanel.showTextHigh;
+ JTextField showMid = ScreenPanel.showTextMid;
+ JTextField showLow = ScreenPanel.showTextLow;
+ StringBuffer highText;//各自显示文本
+ StringBuffer midText;
+ StringBuffer lowText;
+ Function function;//计算方法类
+ double result = 0;//计算结果
+
+ public Key_screenListener() {
+ init();
+ }
+
+
+ void init() {
+ setText();
+ function = new Function();//计算方法集合
+ }
+
+ void setText() {
+ highText = new StringBuffer();
+ midText = new StringBuffer();
+ lowText = new StringBuffer();
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ JButton button = (JButton) e.getSource();
+ String buttonText = button.getText();//获得按键内容
+ String lowTextLastChar;//底行显示文本最后一个字符
+ if (buttonText.matches("[0-9]")) {//按下数字的情况
+ if (!(lowText.toString().equals("-Infinity") || lowText.toString().equals("NaN"))) {//显示是无穷的时候只能清屏
+ if (lowText.length() < 15) {//限制数字长度
+ lowText.append(buttonText);//按下数字后底文本记录
+ //中显示框等号右边无数字时按下数字键,等号右边将添加计算结果
+ if (midText.length() != 0 && midText.toString().
+ charAt(midText.length() - 1) == '=') {
+ midText.append(result);
+ showMid.setText(midText.toString());
+ lowText = new StringBuffer(buttonText);
+ }
+ }
+ showLow.setText(lowText.toString());//显示底屏幕
+ }
+ }
+ if (buttonText.matches("[-+x/%]")) {//按下运算符的情况
+ if (!(lowText.toString().equals("-Infinity") || lowText.toString().equals("NaN"))) {
+
+
+ if (lowText.toString().length() != 0) {//长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ lowText.append(buttonText);
+ }
+ }
+ } else {//长度为0,按下+-,表示正负号,按下其他如“%”,则0%
+ if ("+-".contains(buttonText)) {
+ lowText.append(buttonText);
+ } else {
+ lowText.append("0");
+ lowText.append(buttonText);
+ }
+ }
+ //按下运算符,中显示行等号右边无数字时添加上上次计算的计算结果,底行新起计算
+ if (midText.length() != 0 && midText.toString().
+ charAt(midText.length() - 1) == '=') {
+ midText.append(result);
+ showMid.setText(midText.toString());
+ }
+ showLow.setText(lowText.toString());//用上次计算结果来进行下次计算,底行不变
+ }
+ }
+ if (buttonText.equals(".")) {//按下小数点
+ if (!(lowText.toString().equals("-Infinity") || lowText.toString().equals("NaN"))) {
+ if (lowText.length() == 0) {//按下小数点,底行文本为0时,添加0,变成“0.”
+ lowText.append("0");
+ }
+ //将底文本进行分割成两个操作数,分别只能有1个小数点
+ String s = lowText.toString();
+ if (s.charAt(0) == '-' || s.charAt(0) == '+') {
+ s = s.substring(1);
+ }
+ String[] operand = s.split("[-+x/%^]");//lowText用操作符分割成运算数
+ if (operand.length == 1) {//只有一个操作数时
+ if (!operand[0].contains(".")) {
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ if (!lowTextLastChar.matches("[-+x/%]")) {//小数点前一位不能是运算符
+ lowText.append(buttonText);
+ }
+ }
+ }
+ if (operand.length == 2) {//有两个操作数时,不需考虑操作数1
+ if (!operand[1].contains(".")) {
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ if (!lowTextLastChar.matches("[-+x/%]")) {//小数点前一位不能是运算符
+ lowText.append(buttonText);
+ }
+ }
+ }
+ showLow.setText(lowText.toString());
+ }
+ }
+ if (buttonText.equals("C")) {//按下C初始化显示
+ lowText = new StringBuffer("");
+ midText = new StringBuffer("");
+ highText = new StringBuffer("");
+ showLow.setText("0");
+ showMid.setText(midText.toString());
+ showHigh.setText(highText.toString());
+ }
+ if (buttonText.equals("Del")) {//按下Def键,逐字符删除
+ if (lowText.toString().equals("-Infinity") || lowText.toString().equals("NaN")) {//显示无穷时,删除整条
+ lowText = new StringBuffer("0");
+ showLow.setText(lowText.toString());
+ }
+ if (lowText.length() > 0) {//有字符时删除
+ lowText.deleteCharAt(lowText.length() - 1);
+ showLow.setText(lowText.toString());
+ }
+ if (lowText.length() == 0) {//无字符时补0
+ showLow.setText("0");
+ }
+ }
+ //按下“=”
+ //1.无操作符时不改变
+ //2.有但只有一个操作符也不改变
+ //3. 计算完底行显示结果,计算式移到上一行
+ if (buttonText.equals("=")) {//按下“=”的情况
+ String s = lowText.toString();
+ int count = 0;
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count != 0) {
+ String[] operations = s.split("[-+x/%^]");
+ if (operations.length != 1) {//操作数大于1个才可
+ lowText.append(buttonText);
+ if (showMid.getText().length() != 0) {//中文本长度不为0,按下“=”则中文本内容移到上文本
+ highText = midText;
+ showHigh.setText(highText.toString());
+ }
+ midText = lowText;//底文本的计算式移到中文本
+ showMid.setText(midText.toString());
+ calculate();//进行计算
+ if (!lowText.toString().equals("NaN")) {
+ lowText = new StringBuffer(Double.toString(result));//底显示行仅显示计算结果
+ showLow.setText(lowText.toString());
+ }
+ }
+ }
+ }
+ if (buttonText.equals("x^y")) {//按下x^y的情况
+ if (lowText.length() == 0) {
+ lowText.append("0");
+ }
+ lowTextLastChar = "";
+ if (lowText.length() < 15) {
+ if (lowText.toString().length() != 0) {//长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ }
+ if (lowTextLastChar.matches("[0-9]")) {
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ lowText.append("^");
+ showLow.setText(lowText.toString());
+ }
+ //按下运算符,中显示行等号右边无数字时添加上上次计算的计算结果,底行新起计算
+ if (midText.length() != 0 && midText.toString().
+ charAt(midText.length() - 1) == '=') {
+ midText.append(result);
+ showMid.setText(midText.toString());
+ }
+ showLow.setText(lowText.toString());//用上次计算结果来进行下次计算,底行不变
+ }
+ }
+ }
+ }
+ if (buttonText.equals("x^2")) {//按下x^2键
+ if (lowText.length() == 0) {
+ lowText.append("0");
+ }
+ lowTextLastChar = "";
+ if (lowText.length() < 15) {
+ if (lowText.toString().length() != 0) {//长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ }
+ if (lowTextLastChar.matches("[0-9]")) {
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ lowText.append("^2");
+ showLow.setText(lowText.toString());
+ }
+ }
+ }
+ }
+ }
+ if (buttonText.equals("sqrt")) {//按下sqrt键
+ if (lowText.length() == 0) {
+ lowText.append("0");
+ }
+ if ((lowText.length() != 0) && (!(lowText.toString().charAt(0) == '-'))) {
+ lowTextLastChar = "";
+ if (lowText.length() < 15) {
+ //长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ if (lowTextLastChar.matches("[0-9]")) {
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ lowText.append("^0.5");
+ showLow.setText(lowText.toString());
+ }
+ }
+ }
+ }
+ }
+ }
+ if (buttonText.equals("lnx")) {//按下lnx键
+ if (lowText.length() == 0) {
+ lowText.append("0");
+ }
+ lowTextLastChar = "";
+ if (lowText.length() < 15) {
+ if (lowText.toString().length() != 0) {//长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ }
+ if (lowTextLastChar.matches("[0-9]")) {
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ String temp = lowText.toString();
+ Double logOperation = Double.parseDouble(temp);
+ if (logOperation <= 0) {
+ lowText = new StringBuffer("NaN");
+ showLow.setText(lowText.toString());
+ } else {
+ result = function.logarithm_e(logOperation);
+ BigDecimal bigDecimal = new BigDecimal(result);//限制结果最大长度,四舍五入
+ result = bigDecimal.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
+ lowText = new StringBuffer(String.valueOf(result));
+ showLow.setText(lowText.toString());
+ }
+ }
+ }
+ }
+ }
+ }
+ if (buttonText.equals("lgx")) {//按下lgx键
+ if (lowText.length() == 0) {
+ lowText.append("0");
+ }
+ lowTextLastChar = "";
+ if (lowText.length() < 15) {
+ if (lowText.toString().length() != 0) {//长度不为0,判断最后字符是不是运算符
+ lowTextLastChar = Character.toString(
+ lowText.toString().charAt(lowText.length() - 1));
+ }
+ if (lowTextLastChar.matches("[0-9]")) {
+ if (!("-+x/%.^".contains(lowTextLastChar))) {//两个数之间只能有一个运算符且小数点后不能接运算符
+ String s = lowText.toString();
+ int count = 0;
+ //“+”“-”不是第一个字符则一个式子只能有一个运算符
+ for (int i = 0; i < s.length(); i++) {
+ if (s.charAt(i) == 'x') {
+ count++;
+ } else if (s.charAt(i) == '/') {
+ count++;
+ } else if (s.charAt(i) == '%') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '+') {
+ count++;
+ } else if (i != 0 && s.charAt(i) == '-') {
+ count++;
+ } else if (s.charAt(i) == '^') {
+ count++;
+ }
+ }
+ if (count == 0) {//按下运算符键时底行文本无运算符才可以添加运算符,即一行只有一个计算符
+ String temp = lowText.toString();
+ Double logOperation = Double.parseDouble(temp);
+ if (logOperation <= 0) {
+ lowText = new StringBuffer("NaN");
+ showLow.setText(lowText.toString());
+ } else {
+ result = function.logarithm_10(logOperation);
+ BigDecimal bigDecimal = new BigDecimal(result);//限制结果最大长度,四舍五入
+ result = bigDecimal.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
+ lowText = new StringBuffer(String.valueOf(result));
+ showLow.setText(lowText.toString());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void calculate() {//计算
+ String s = lowText.toString();
+ String[] operations = s.split("[-+x/%=^]");
+ double operation1 = 0;//得到底文本的两个操作数
+ double operation2 = 0;
+ //第一个操作数若是负数,第一个串会是空串,忽略掉
+ if (operations[0].length() != 0) {//无空串
+ operation1 = Double.parseDouble(operations[0]);
+ operation2 = Double.parseDouble(operations[1]);
+ } else {//有空串
+ operation1 = Double.parseDouble(operations[1]);
+ operation2 = Double.parseDouble(operations[2]);
+ if (s.charAt(0) == '-') {//首字符是‘-’,操作数为负数
+ operation1 = -operation1;
+ }
+ }
+ //底行首字符是正负号情况下,分别讨论后面操作符不同时的运算
+ //其他的底行中至多只有一个,不需分别讨论
+ if (s.charAt(0) == '+' && (s.substring(1).contains("+"))) {
+ result = function.add(operation1, operation2);
+ } else if (s.charAt(0) == '+' && (s.substring(1).contains("-"))) {
+ result = function.subtract(operation1, operation2);
+ } else if (s.charAt(0) == '-' && (s.substring(1).contains("-"))) {
+ result = function.subtract(operation1, operation2);
+ } else if (s.charAt(0) == '-' && (s.substring(1).contains("+"))) {
+ result = function.add(operation1, operation2);
+ } else if (s.contains("x")) {
+ result = function.multiply(operation1, operation2);
+ } else if (s.contains("/")) {
+ if (operation2 == 0) {//除0不可计算
+ lowText = new StringBuffer("NaN");
+ showLow.setText(lowText.toString());
+ } else {
+ result = function.divide(operation1, operation2);
+ }
+ } else if (s.contains("%")) {
+ if (operation2 == 0) {//模0不可计算
+ lowText = new StringBuffer("NaN");
+ showLow.setText(lowText.toString());
+ } else {
+ result = function.modulo(operation1, operation2);
+ }
+
+ } else if (s.contains("^")) {
+ if (operation1 < 0 && Math.abs(operation2) < 1) {
+ lowText = new StringBuffer("NaN");
+ showLow.setText(lowText.toString());
+ } else {
+ result = function.pow(operation1, operation2);
+ }
+ } else if (s.contains("+")) {
+ result = function.add(operation1, operation2);
+ } else if (s.contains("-")) {
+ result = function.subtract(operation1, operation2);
+ }
+ BigDecimal bigDecimal = new BigDecimal(result);//限制结果最大长度,四舍五入
+ result = bigDecimal.setScale(6, BigDecimal.ROUND_HALF_UP).doubleValue();
+ }
+}
diff --git a/src/SwingEvents/OptionActionListener.java b/src/SwingEvents/OptionActionListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..dff23351b500eb29073a9fcd7bb3b6fb2663cc41
--- /dev/null
+++ b/src/SwingEvents/OptionActionListener.java
@@ -0,0 +1,25 @@
+package SwingEvents;
+
+import AppMain.Main;
+import UI.SimpleCalculatorUI.Panel.OptionPanel;
+
+import javax.swing.*;
+import java.awt.event.*;
+
+/**
+ * @ClassName:OptionListener
+ * @Description:监听设置面板发生的事件,如关闭、最小化窗口按钮事件、顶部按钮事件
+ * @Author:LMD傻蛋
+ * @Date:2022/5/19 21 29
+ * @version:v1.0
+ */
+public class OptionActionListener implements ActionListener {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if (e.getSource() == OptionPanel.minimize) {//按下最小化按键
+ Main.win.setExtendedState(JFrame.ICONIFIED);//最小化窗口
+ } else if (e.getSource() == OptionPanel.close) {//按下关闭键
+ System.exit(0);
+ }
+ }
+}
diff --git a/src/SwingEvents/OptionMouseListener.java b/src/SwingEvents/OptionMouseListener.java
new file mode 100644
index 0000000000000000000000000000000000000000..cff710dd232c3ff0811c02f0b65be1f966c18de8
--- /dev/null
+++ b/src/SwingEvents/OptionMouseListener.java
@@ -0,0 +1,33 @@
+package SwingEvents;
+
+import AppMain.Main;
+import UI.SimpleCalculatorUI.Panel.OptionPanel;
+
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+
+/**
+ * @ClassName:OptionMouseListener
+ * @Description:设置栏鼠标事件监听,鼠标拖动设置条时移动窗口
+ * @Author:LMD傻蛋
+ * @Date:2022/5/19 22 39
+ * @version:v1.0
+ */
+public class OptionMouseListener implements MouseMotionListener {
+ @Override
+ public void mouseDragged(MouseEvent e) {//拖动鼠标时窗口移动
+ Point p = Main.win.getLocation();
+ //当前窗口位置+当前鼠标位置-按下时窗口位置
+ Main.win.setLocation(p.x + e.getX() - OptionPanel.point.x,
+ p.y + e.getY() - OptionPanel.point.y);
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+
+ }
+}
+
+
diff --git a/src/UI/SimpleCalculatorUI/Panel/BottomPanel.java b/src/UI/SimpleCalculatorUI/Panel/BottomPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..32b3e24322ab3e93d4fa13ec34ffe8eb80574936
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/BottomPanel.java
@@ -0,0 +1,52 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @ClassName:BottomPanel
+ * @Description:底层面板&背景面板
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 43
+ * @version:v1.0
+ */
+public class BottomPanel extends JPanel {
+ int BottomPanel_X;
+ int BottomPanel_Y;
+ int BottomPanel_Width;
+ int BottomPanel_Height;
+ int backGroundArc = 100;//背景圆角弧度
+ ForePanel forePanel;//表置面板
+ Color backGroundColor = new Color(40, 51, 69);//背景颜色
+
+
+ public BottomPanel(int x, int y, int width, int height) {
+ this.BottomPanel_X = x;
+ this.BottomPanel_Y = y;
+ this.BottomPanel_Width = width;
+ this.BottomPanel_Height = height;
+ init();
+ }
+
+ private void init() {
+ forePanel = new ForePanel(0, 0, BottomPanel_Width, BottomPanel_Height);
+ this.add(forePanel);
+ this.setLayout(null);//空布局
+ this.setBounds(BottomPanel_X, BottomPanel_Y,
+ BottomPanel_Width, BottomPanel_Height);
+ }
+
+
+ @Override
+ protected void paintComponent(Graphics g) {
+// setOpaque(false);//组件透明
+// super.paintComponent(g);
+ g.setColor(backGroundColor);//设置画笔颜色
+ g.fillRoundRect(BottomPanel_X, BottomPanel_Y, BottomPanel_Width,
+ BottomPanel_Height, backGroundArc, backGroundArc);//画出背景
+// ((Graphics2D) g).setRenderingHint(
+// RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//抗锯齿
+// ((Graphics2D) g).setStroke(
+// new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));//边线圆滑
+ }
+}
diff --git a/src/UI/SimpleCalculatorUI/Panel/ForePanel.java b/src/UI/SimpleCalculatorUI/Panel/ForePanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..7640fa95793757d65577df0b6694f4c78b75c4ce
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/ForePanel.java
@@ -0,0 +1,47 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import javax.swing.*;
+
+/**
+ * @ClassName:ForePanel
+ * @Description:前端面板,将键盘面板、显示面板、设置面板组合在一起
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 44
+ * @version:v1.0
+ */
+public class ForePanel extends JPanel {
+ int ForePanel_X;
+ int ForePanel_Y;
+ int ForePanel_Width;
+ int ForePanel_Height;
+ OptionPanel optionPanel;//设置栏面板
+ ScreenPanel screenPanel;//显示面板
+ public KeyPanel keyPanel = new KeyPanel();//按键面板
+
+ public ForePanel(int forePanel_X, int forePanel_Y,
+ int forePanel_Width, int forePanel_Height) {
+ ForePanel_X = forePanel_X;
+ ForePanel_Y = forePanel_Y;
+ ForePanel_Width = forePanel_Width;
+ ForePanel_Height = forePanel_Height;
+ init();
+ }
+
+ private void init() {
+ optionPanel = new OptionPanel(0,
+ 0, this.ForePanel_Width, 60);
+ screenPanel = new ScreenPanel(0,
+ optionPanel.OptionPanel_Height, this.ForePanel_Width, 120);
+ keyPanel = new KeyPanel(0,
+ optionPanel.OptionPanel_Height + screenPanel.h,
+ ForePanel_Width, 500);
+ this.add(optionPanel);
+ this.add(screenPanel);
+ this.add(keyPanel);
+ this.setBounds(0, 0, ForePanel_Width, ForePanel_Height);
+ this.setLayout(null);//设为空布局
+ this.setOpaque(false);//设为透明
+ }
+
+
+}
diff --git a/src/UI/SimpleCalculatorUI/Panel/KeyPanel.java b/src/UI/SimpleCalculatorUI/Panel/KeyPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..e26d518a1ff4c0cc3c964eb1604f1ceb7217528c
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/KeyPanel.java
@@ -0,0 +1,151 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import SwingEvents.Key_screenListener;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import java.awt.*;
+
+/**
+ * @ClassName:KeyPanel
+ * @Description:键盘面板,按键组合在一起形成
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 45
+ * @version:v1.0
+ */
+public class KeyPanel extends JPanel {
+ int KeyPanel_X;
+ int KeyPanel_Y;
+ int KeyPanel_Width;
+ int KeyPanel_Height;//坐标与大小
+ int keyArc = 50;//按键圆角的弧长
+ int KeyHDistance = 26;//按键横距
+ int KeyVDistance = 20;//按键纵距
+ int KeySideLen = 80;//按键边长
+ Color keyColor = new Color(38, 38, 38);//按键背景
+ RoundRectKey[] keys;//按键数组
+ JButton[] moreKeys = SelectPanel.selections;//引入几个科学计算键
+ public Key_screenListener key_screenListener = new Key_screenListener();//按键监听
+
+ public KeyPanel() {
+ }
+
+
+ public KeyPanel(int keyPanel_X, int keyPanel_Y, int keyPanel_Width, int keyPanel_Height) {
+ KeyPanel_X = keyPanel_X;
+ KeyPanel_Y = keyPanel_Y;
+ KeyPanel_Width = keyPanel_Width;
+ KeyPanel_Height = keyPanel_Height;
+ init();
+ }
+
+ private void init() {
+ setLayout(null);//空布局
+ this.setOpaque(false);//透明
+ this.setBounds(KeyPanel_X, KeyPanel_Y, KeyPanel_Width, KeyPanel_Height);
+ setButtons();//创建19个按键
+ }
+
+ private void setButtons() {
+ JPanel panel1 = new JPanel();//按键分放在两个子面板
+ JPanel panel2 = new JPanel();
+ panel1.setLayout(new GridLayout(4, 4, KeyHDistance, KeyVDistance));//面板1放16个按键,网格布局
+ panel2.setLayout(null);//面板2空布局
+ panel1.setOpaque(false);//均不可见
+ panel2.setOpaque(false);
+ panel1.setBounds(KeyHDistance, 0, this.KeyPanel_Width - 2 * KeyHDistance,
+ this.KeyPanel_Height - KeySideLen - KeyVDistance);
+ panel2.setBounds(KeyHDistance, panel1.getHeight() + KeyVDistance,
+ KeyPanel_Width - 2 * KeyHDistance, KeySideLen + KeyVDistance);
+ String[] keyNames = {"C", "Del", "%", "/",
+ "7", "8", "9", "x", "4", "5", "6",
+ "-", "1", "2", "3", "+", "0", ".", "="};//各按键名
+ keys = new RoundRectKey[19];
+ for (int i = 0; i < keys.length; i++) {
+ keys[i] = new RoundRectKey();
+ keys[i].setText(keyNames[i]);//设置按键内容
+ keys[i].setPreferredSize(new Dimension(KeySideLen, KeySideLen));//设置按键边长
+ if (i < 16) {
+ panel1.add(keys[i]);
+ }
+ }
+ for (int i = 0; i < moreKeys.length; i++) {
+ moreKeys[i].addActionListener(key_screenListener);
+ }
+ //最后3个按键分别设置
+ keys[16].setBounds(0, 0, KeySideLen, KeySideLen);
+ keys[17].setBounds(KeySideLen + KeyHDistance, 0, KeySideLen, KeySideLen);
+ keys[18].setBounds(2 * (KeySideLen + KeyHDistance), 0, 2 * KeySideLen + KeyHDistance, KeySideLen);
+ setKeyColor(keys);//给特定按键设不同颜色
+ panel2.add(keys[16]);
+ panel2.add(keys[17]);
+ panel2.add(keys[18]);
+ this.add(panel1);
+ this.add(panel2);
+ }
+
+ private void setKeyColor(RoundRectKey[] keys) {//特别案件颜色方法
+ for (int i = 0; i < keys.length; i++) {
+ if ("+-x/%".contains(keys[i].getText())) {
+ keys[i].setForeground(new Color(228, 121, 48));
+ }
+ if ("=".equals(keys[i].getText())) {
+ keys[i].setForeground(new Color(255, 0, 0));
+ }
+ if ("C".equals(keys[i].getText())) {
+ keys[i].setForeground(Color.CYAN);
+ }
+ if ("Del".equals(keys[i].getText())) {
+ keys[i].setForeground(new Color(255, 255, 102));
+ }
+ }
+ }
+
+ class RoundRectKey extends JButton {//按键样式
+
+ class RoundRectBorder implements Border {//按键边界
+
+ @Override
+ public Insets getBorderInsets(Component c) {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ @Override
+ public boolean isBorderOpaque() {
+ return false;
+ }
+
+ @Override
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height) {
+ //使用黑色在组件的外边缘绘制一个圆角矩形
+ g.setColor(keyColor);
+ g.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), keyArc, keyArc);
+ }
+ }
+
+ public RoundRectKey() {
+ setMargin(new Insets(0, 0, 0, 0));//去除文字与按钮的边沿
+ setBorder(new RoundRectBorder());//圆角矩形边界
+ setContentAreaFilled(false);//取消原先画矩形的设置
+ setBorderPainted(false);//隐藏按钮明显边界
+ setFocusPainted(false);//去除文字周围的虚线框
+ setBackground(keyColor);//设置按键背景色
+ setForeground(Color.WHITE);//按键内容颜色
+ setFont(new Font("等线(正文)", Font.PLAIN, 30));//设置字体
+ addActionListener(key_screenListener);//添加按键监听
+ }
+
+ protected void paintComponent(Graphics g) {//填充按钮
+ if (getModel().isArmed()) {//按键被按下显绿色
+ g.setColor(Color.GREEN);
+ } else {
+ g.setColor(getBackground());
+ }
+
+ g.fillRoundRect(0, 0, getSize().width, getSize().height, keyArc, keyArc);//填充圆角矩形边界
+ // 绘制按钮
+ super.paintComponent(g);
+ }
+ }
+}
diff --git a/src/UI/SimpleCalculatorUI/Panel/OptionPanel.java b/src/UI/SimpleCalculatorUI/Panel/OptionPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..2609961743ee14bdbb3a6fff38290e8fb561e262
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/OptionPanel.java
@@ -0,0 +1,184 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import AppMain.Main;
+import SwingEvents.OptionActionListener;
+import SwingEvents.OptionMouseListener;
+import UI.SimpleCalculatorUI.Win;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+/**
+ * @ClassName:OptionPanel
+ * @Description:设置面板,一个小框,放移动条、关闭、最小化按钮
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 50
+ * @version:v1.0
+ */
+public class OptionPanel extends JPanel {
+
+ public static int OptionPanel_X;
+ public static int OptionPanel_Y;
+ public static int OptionPanel_Width;
+ public static int OptionPanel_Height;
+ public static JButton minimize;//最小化按钮
+ public static JButton close;//关闭按钮
+ public static JButton menuBar;//菜单键
+ public static Point point;//鼠标位置
+ OptionActionListener optionListener;//设置栏按钮监听器
+ OptionMouseListener optionMouseListener;
+
+ public OptionPanel(int optionPanel_X, int optionPanel_Y,
+ int optionPanel_Width, int optionPanel_Height) {
+ OptionPanel_X = optionPanel_X;
+ OptionPanel_Y = optionPanel_Y;
+ OptionPanel_Width = optionPanel_Width;
+ OptionPanel_Height = optionPanel_Height;
+ init();
+ }
+
+ private void init() {
+ setLayout(null);
+ setOpaque(false);//透明
+ setBounds(OptionPanel_X, OptionPanel_Y, OptionPanel_Width, OptionPanel_Height);
+ setButton_Menu();//设置各按钮
+ optionListener = new OptionActionListener();
+ optionMouseListener = new OptionMouseListener();
+ minimize.addActionListener(optionListener);//各按钮添加监视器
+ close.addActionListener(optionListener);
+ menuBar.addActionListener(optionListener);
+ menuBar.addMouseMotionListener(optionMouseListener);
+ menuBar.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {//记录按下设置按钮时鼠标相对于组件的位置
+ point = e.getPoint();
+ }
+
+ @Override
+ public void mouseClicked(MouseEvent e) {//选项栏未展开则单击按钮展开选项栏,再单击收回
+ if (Main.win.getHeight() > 700) {
+ SelectPanel.isOpen = true;
+ }
+ if (!SelectPanel.isOpen) {
+ Main.win.setBounds(Main.win.getX(), Main.win.getY() - 90, 450,
+ Main.win.getHeight() + 90);//展开选项栏增大窗口
+ Win.bottomPanel.setBounds(0, 90, 450, 700);//底面板下移
+ Main.win.add(Win.selectPanel);
+ } else if (Main.win.getHeight() > 700) {//收回选项栏
+ Main.win.remove(Win.selectPanel);//移除选项栏
+ Win.bottomPanel.setBounds(0, 0, 450, 700);//恢复窗口及原面板大小与位置
+ Main.win.setBounds(Main.win.getX(), Main.win.getY() + 90, 450, 700);
+ SelectPanel.isOpen = false;
+ }
+ }
+ });
+ }
+
+ private void setButton_Menu() {
+ minimize = new RoundButton();
+ close = new RoundButton();
+ menuBar = new RoundRectButton();
+ add(minimize);
+ add(menuBar);
+ add(close);
+ minimize.setBounds(60, 0, 60, 60);
+ menuBar.setBounds(125, 0, 200, 40);
+ close.setBounds(330, 0, 60, 60);
+ minimize.setText("--");
+ close.setText("X");
+ minimize.setForeground(Color.WHITE);
+ close.setForeground(Color.RED);
+ menuBar.setText("MORE");
+ menuBar.setForeground(Color.PINK);
+ }
+
+ class RoundButton extends JButton {//圆按键(最小化、关闭)
+
+ public RoundButton() {
+ setFocusPainted(false);//去除文字周围的虚线框
+ setBorder(new RoundBorder());//圆边界
+ setContentAreaFilled(false);//取消原先画矩形的设置
+ setBorderPainted(false);//隐藏按钮明显边界
+ setBackground(new Color(175, 171, 171));//设置按键背景色
+ setFont(new Font("等线(正文)", Font.PLAIN, 30));//设置字体
+ }
+
+ class RoundBorder implements Border {//(按钮)圆边界类
+
+ @Override
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height) {
+ g.setColor(new Color(175, 171, 171));
+ g.drawOval(0, 0, c.getWidth(), c.getHeight());
+ }
+
+ @Override
+ public Insets getBorderInsets(Component c) {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ @Override
+ public boolean isBorderOpaque() {
+ return false;
+ }
+ }
+
+ @Override
+ protected void paintComponent(Graphics g) {//绘制组件使更改内容显示
+ if (getModel().isArmed()) {//按下按键显色否则为背景色
+ g.setColor(Color.RED);
+ } else {
+ g.setColor(getBackground());
+ }
+ ((Graphics2D) g).setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//抗锯齿
+ g.fillOval(0, 0, getSize().width, getSize().height);//填充边界
+ super.paintComponent(g);//绘
+ }
+ }
+
+
+ class RoundRectButton extends JButton {//圆角矩形按键(菜单)
+
+ class RoundRectBorder implements Border {//圆角矩形边界
+
+ @Override
+ public Insets getBorderInsets(Component c) {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ @Override
+ public boolean isBorderOpaque() {
+ return false;
+ }
+
+ @Override
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height) {
+ //使用黑色在组件的外边缘绘制一个圆角矩形
+ g.setColor(new Color(175, 171, 171));
+ g.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), 20, 20);
+
+ }
+ }
+
+ public RoundRectButton() {
+ setMargin(new Insets(0, 0, 0, 0));//去除文字与按钮的边沿
+ setBorder(new RoundRectBorder());//设置圆角矩形边界
+ setContentAreaFilled(false);//取消原先画矩形的设置
+ setBorderPainted(false);//隐藏按钮明显边界
+ setFocusPainted(false);//去除文字周围的虚线框
+ setBackground(new Color(59, 56, 56));//设置按键背景色
+ }
+
+ protected void paintComponent(Graphics g) {//绘制
+ g.setColor(getBackground());
+ g.fillRect(0, 0, getSize().width, getSize().height);//填充圆角矩形边界
+ super.paintComponent(g);//绘
+ }
+ }
+}
+
diff --git a/src/UI/SimpleCalculatorUI/Panel/ScreenPanel.java b/src/UI/SimpleCalculatorUI/Panel/ScreenPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..662362c008c3f73893f26a41a677768509239bb4
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/ScreenPanel.java
@@ -0,0 +1,72 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @ClassName:ScreenPanel_First
+ * @Description:显示面板——计算过程的数字在此面板显示
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 45
+ * @version:v1.0
+ */
+public class ScreenPanel extends JPanel {
+ int x, y, w, h;
+ JPanel showArea;//显示面板,便于将显示文本框放置
+ static public JTextField showTextHigh;//顶中下三个文本框
+ static public JTextField showTextMid;
+ static public JTextField showTextLow;
+
+ public void setShowArea() {
+ showArea = new JPanel();
+ showArea.setOpaque(false);//显示面板透明
+ showArea.setLayout(null);
+ //面板大小,宽度450,左右留白26的宽
+ showArea.setBounds(26, 10, 398, 90);
+ showTextHigh = new JTextField();
+ showTextMid = new JTextField();
+ showTextLow = new JTextField();
+ showTextLow.setText("0");//初始时显示0
+ showTextHigh.setBounds(0, 0, 398, 30);
+ showTextMid.setBounds(0, 30, 398, 30);
+ showTextLow.setBounds(0, 60, 398, 30);
+ showArea.add(showTextHigh);
+ showArea.add(showTextMid);
+ showArea.add(showTextLow);
+ Font showTextFont = new Font("等线(正文)", Font.PLAIN, 35);//显示字体
+ showTextHigh.setFont(showTextFont);
+ showTextMid.setFont(showTextFont);
+ showTextLow.setFont(showTextFont);
+ showTextHigh.setOpaque(false);//文本框不可见
+ showTextMid.setOpaque(false);
+ showTextLow.setOpaque(false);
+ showTextHigh.setForeground(Color.GRAY);//顶部文本框字体灰色
+ showTextMid.setForeground(Color.LIGHT_GRAY);//中间轻灰
+ showTextLow.setForeground(Color.WHITE);//下部输入数字在此显示,白色
+ showTextHigh.setHorizontalAlignment(JTextField.RIGHT);//从右往左输入
+ showTextMid.setHorizontalAlignment(JTextField.RIGHT);
+ showTextLow.setHorizontalAlignment(JTextField.RIGHT);
+ showTextHigh.setBorder(null);//去掉文本边框
+ showTextMid.setBorder(null);
+ showTextLow.setBorder(null);
+ showTextHigh.setFocusable(false);//不可聚焦
+ showTextMid.setFocusable(false);
+ showTextLow.setFocusable(false);
+ }
+
+ public ScreenPanel(int x, int y, int w, int h) {
+ this.x = x;
+ this.y = y;
+ this.w = w;
+ this.h = h;
+ init();
+ }
+
+ private void init() {
+ setLayout(null);
+ setOpaque(false);//本面板透明
+ setBounds(x, y, w, h);
+ setShowArea();
+ add(showArea);//显示面板加入到此面板
+ }
+}
diff --git a/src/UI/SimpleCalculatorUI/Panel/SelectPanel.java b/src/UI/SimpleCalculatorUI/Panel/SelectPanel.java
new file mode 100644
index 0000000000000000000000000000000000000000..117dd889e5dbbc9725feb1e5982001e8d71c2183
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Panel/SelectPanel.java
@@ -0,0 +1,98 @@
+package UI.SimpleCalculatorUI.Panel;
+
+import javax.swing.*;
+import javax.swing.border.Border;
+import java.awt.*;
+
+/**
+ * @ClassName:SelectPanel
+ * @Description:选项按钮面板
+ * @Author:LMD傻蛋
+ * @Date:2022/5/20 13 09
+ * @version:v1.0
+ */
+public class SelectPanel extends JPanel {
+ public static boolean isOpen = false;
+ public static RoundRectKey[] selections;
+ JPanel buttonPanel = new JPanel();//按键面板
+ String[] buttonNames = {"x^y", "x^2", "sqrt", "lnx", "", "lgx"};//选项名
+
+ public SelectPanel() {
+ init();
+ }
+
+ void init() {
+ setBounds(125, 0, 200, 90);
+ setBackground(new Color(59, 56, 56));//设置背景色
+ setButtons();//设置按钮
+ buttonPanel.setBounds(20, 0, 160, 90);
+ buttonPanel.setLayout(new GridLayout(2, 3, 20, 5));
+ buttonPanel.setOpaque(false);
+ add(buttonPanel);
+ }
+
+ void setButtons() {
+ selections = new RoundRectKey[6];
+ for (int i = 0; i < selections.length; i++) {
+ selections[i] = new RoundRectKey();
+ add(selections[i]);
+ selections[i].setHorizontalAlignment(JButton.CENTER);//文字居中
+ selections[i].setPreferredSize(new Dimension(40, 40));//按钮大小
+ buttonPanel.add(selections[i]);
+ selections[i].setText(buttonNames[i]);
+ }
+ //第5个按钮填图
+ ImageIcon image = new ImageIcon("D:\\Daily\\JAVA\\IDEA\\2022_Spring_0109_calculator/904c00f112f7e8e7e310e60a24830c6.jpg");
+ image.setImage(image.getImage().getScaledInstance(40, 40, 0));//缩小图片
+ selections[4].setIcon(image);
+ }
+
+ class RoundRectKey extends JButton {//按键样式
+
+ class RoundRectBorder implements Border {//按键边界
+
+ @Override
+ public Insets getBorderInsets(Component c) {
+ return new Insets(0, 0, 0, 0);
+ }
+
+ @Override
+ public boolean isBorderOpaque() {
+ return false;
+ }
+
+ @Override
+ public void paintBorder(Component c, Graphics g, int x, int y,
+ int width, int height) {
+ //使用黑色在组件的外边缘绘制一个圆角矩形
+ g.setColor(Color.white);
+ g.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), 20, 20);
+ }
+ }
+
+ public RoundRectKey() {
+ setMargin(new Insets(0, 0, 0, 0));//去除文字与按钮的边沿
+ setBorder(new RoundRectBorder());//圆角矩形边界
+ setContentAreaFilled(false);//取消原先画矩形的设置
+ setBorderPainted(false);//隐藏按钮明显边界
+ setFocusPainted(false);//去除文字周围的虚线框
+ setBackground(Color.WHITE);//设置按键背景色
+ setForeground(Color.BLACK);//按键内容颜色
+ setFont(new Font("等线(正文)", Font.BOLD, 15));//设置字体
+ }
+
+ protected void paintComponent(Graphics g) {//填充按钮
+ if (getModel().isArmed()) {//按键被按下显黄色
+ g.setColor(Color.ORANGE);
+ } else {
+ g.setColor(getBackground());
+ }
+ ((Graphics2D) g).setRenderingHint(
+ RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//抗锯齿
+
+ g.fillRoundRect(0, 0, getSize().width, getSize().height, 20, 20);//填充圆角矩形边界
+ // 绘制按钮
+ super.paintComponent(g);
+ }
+ }
+}
diff --git a/src/UI/SimpleCalculatorUI/Win.java b/src/UI/SimpleCalculatorUI/Win.java
new file mode 100644
index 0000000000000000000000000000000000000000..711945843478aa0e99fe1daf74fa705565aa3b5e
--- /dev/null
+++ b/src/UI/SimpleCalculatorUI/Win.java
@@ -0,0 +1,64 @@
+package UI.SimpleCalculatorUI;
+
+import UI.SimpleCalculatorUI.Panel.BottomPanel;
+import UI.SimpleCalculatorUI.Panel.SelectPanel;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @ClassName:Win
+ * @Description:基础计算器的窗口
+ * @Author:LMD傻蛋
+ * @Date:2022/5/18 22 40
+ * @version:v1.0
+ */
+public class Win extends JFrame {
+ //窗体坐标与长度、宽度
+ int Win_X;
+ int Win_Y;
+ int Win_Width;
+ int Win_Height;
+
+ public static BottomPanel bottomPanel;//声明基面板
+ public static SelectPanel selectPanel = new SelectPanel();//选择面板
+
+
+ public int getWin_X() {
+ return Win_X;
+ }
+
+ public int getWin_Y() {
+ return Win_Y;
+ }
+
+ public int getWin_Width() {
+ return Win_Width;
+ }
+
+ public int getWin_Height() {
+ return Win_Height;
+ }
+
+ public Win(int win_X, int win_Y, int
+ win_Width, int win_Height) throws HeadlessException {
+ this.Win_X = win_X;
+ this.Win_Y = win_Y;
+ this.Win_Width = win_Width;
+ this.Win_Height = win_Height;
+ init();
+ }
+
+ public void init() {
+ setBounds(Win_X, Win_Y, Win_Width, Win_Height);//设置窗体位置与大小
+ bottomPanel = new BottomPanel(0, 0, Win_Width, Win_Height);
+ add(bottomPanel);//添加底部面板
+ setResizable(false);//不可缩放
+ setUndecorated(true);//无标题
+ setBackground(new Color(255, 255, 255, 0));//背景透明
+ setLayout(null);
+ setVisible(true);//可视化
+ setDefaultCloseOperation(EXIT_ON_CLOSE);//点X关闭
+ }
+}
+
diff --git a/src/java2022spring/Test.java b/src/java2022spring/Test.java
deleted file mode 100644
index 24deb29bfc0e5f50fdedcd21b504e77b529d48b6..0000000000000000000000000000000000000000
--- a/src/java2022spring/Test.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package java2022spring;
-
-public class Test {
- public static void main(String[] args) {
- System.out.println("Hello world!");
- }
-}