From ddbd39bb8f55f57cd143f5c5e1b4e483871d4437 Mon Sep 17 00:00:00 2001 From: Lia Date: Fri, 27 May 2022 19:16:35 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B7=B2=E5=BB=BA=E6=88=90=E5=A4=96?= =?UTF-8?q?=E8=A7=82=EF=BC=8C=E6=8C=89=E9=94=AE=E6=93=8D=E4=BD=9C=E6=96=B9?= =?UTF-8?q?=E9=9D=A2=E8=83=BD=E6=89=A7=E8=A1=8C=EF=BC=8Cpi=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E5=B0=9A=E6=9C=AA=E8=AE=BE=E7=BD=AE=EF=BC=8C"=3D"?= =?UTF-8?q?=E7=9A=84=E6=89=A7=E8=A1=8C=E8=BF=98=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/JSQ.java | 124 +++++++++++++++++++++++++++ src/java2022spring/LiaCaculator.java | 9 ++ 2 files changed, 133 insertions(+) create mode 100644 src/java2022spring/JSQ.java create mode 100644 src/java2022spring/LiaCaculator.java diff --git a/src/java2022spring/JSQ.java b/src/java2022spring/JSQ.java new file mode 100644 index 0000000..15b6557 --- /dev/null +++ b/src/java2022spring/JSQ.java @@ -0,0 +1,124 @@ +package java2022spring; +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +public class JSQ extends JFrame implements ActionListener{ + String [] KEYS= {"AC","+/-","sqr","+","7","8","9","-","4","5","6","*","1","2","3","/","0","π",".","="}; +JButton keys[]=new JButton[KEYS.length]; +JTextField text=new JTextField(50); +double num1,num2; +String string1; +String string2; +double result_double; +String result_string; +String b="+"; +boolean root=false;//记录是否有过操作 + public JSQ() { + JFrame frame = new JFrame("Lia's caculator"); + frame.setBounds(10, 10, 300, 400); + frame.setLayout(new BorderLayout()); + text.setHorizontalAlignment(JTextField.RIGHT); + JPanel pan1=new JPanel(); + pan1.setLayout(new GridLayout(5,4,10,10)); + pan1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + for(int i=0;i Date: Fri, 27 May 2022 20:57:52 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E5=88=B6=E4=BD=9C=EF=BC=8C=E5=8F=AF=E6=AD=A3?= =?UTF-8?q?=E5=B8=B8=E8=BF=90=E8=A1=8C=EF=BC=8C=E5=B9=B6=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E7=AE=80=E5=8D=95=E7=9A=84=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/JSQ.java | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/java2022spring/JSQ.java b/src/java2022spring/JSQ.java index 15b6557..ad97df7 100644 --- a/src/java2022spring/JSQ.java +++ b/src/java2022spring/JSQ.java @@ -7,9 +7,8 @@ public class JSQ extends JFrame implements ActionListener{ String [] KEYS= {"AC","+/-","sqr","+","7","8","9","-","4","5","6","*","1","2","3","/","0","π",".","="}; JButton keys[]=new JButton[KEYS.length]; JTextField text=new JTextField(50); -double num1,num2; -String string1; -String string2; +double num1=0,num2=0; +String string1="0"; double result_double; String result_string; String b="+"; @@ -27,7 +26,11 @@ boolean root=false;// keys[i].setText(KEYS[i]); pan1.add(keys[i]); } - + for(int i=0;i Date: Fri, 27 May 2022 23:28:39 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/JSQ.java | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/src/java2022spring/JSQ.java b/src/java2022spring/JSQ.java index ad97df7..8e895da 100644 --- a/src/java2022spring/JSQ.java +++ b/src/java2022spring/JSQ.java @@ -4,7 +4,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class JSQ extends JFrame implements ActionListener{ - String [] KEYS= {"AC","+/-","sqr","+","7","8","9","-","4","5","6","*","1","2","3","/","0","π",".","="}; + String [] KEYS= {"AC","+/-","sqr","+","Back","7","8","9","-","e","4","5","6","*","sin","1","2","3","/","x^2","0","π",".","=","tan"}; JButton keys[]=new JButton[KEYS.length]; JTextField text=new JTextField(50); double num1=0,num2=0; @@ -15,11 +15,11 @@ String b="+"; boolean root=false;//记录是否有过操作 public JSQ() { JFrame frame = new JFrame("Lia's caculator"); - frame.setBounds(10, 10, 300, 400); + frame.setBounds(10, 10, 400, 400); frame.setLayout(new BorderLayout()); text.setHorizontalAlignment(JTextField.RIGHT); JPanel pan1=new JPanel(); - pan1.setLayout(new GridLayout(5,4,10,10)); + pan1.setLayout(new GridLayout(5,5,10,10)); pan1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); for(int i=0;i0) { + text.setText(old.substring(0,old.length()-1)); + } + } + else if("e".equals(xin)) { + String s=String.valueOf(2.7182818284); + xin=old+s; + text.setText(xin); + } + else if("sin".equals(xin)) { + num1=Double.parseDouble(old); + num1=Math.sin(num1); + text.setText(Double.toString(num1)); + } + else if("x^2".equals(xin)) { + num1=Double.parseDouble(old); + result_double=num1*num1; + result_string=Double.toString(result_double); + text.setText(result_string); + } + else if("tan".equals(xin)) { + num1=Double.parseDouble(old); + num1=Math.tan(num1); + text.setText(Double.toString(num1)); + } } } \ No newline at end of file -- Gitee From f098e8b692b60e0c266ee6cbd4d85c2376588fcf Mon Sep 17 00:00:00 2001 From: Lia Date: Sat, 28 May 2022 13:34:00 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=B7=B2=E5=AE=8C=E5=96=84=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E5=8A=9F=E8=83=BD=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/JSQ.java | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/java2022spring/JSQ.java b/src/java2022spring/JSQ.java index 8e895da..e8af34b 100644 --- a/src/java2022spring/JSQ.java +++ b/src/java2022spring/JSQ.java @@ -4,7 +4,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class JSQ extends JFrame implements ActionListener{ - String [] KEYS= {"AC","+/-","sqr","+","Back","7","8","9","-","e","4","5","6","*","sin","1","2","3","/","x^2","0","π",".","=","tan"}; + String [] KEYS= {"AC","+/-","sqr","+","Back","7","8","9","-","e","4","5","6","*","log","1","2","3","/","x^2","0","π",".","=","1/x"}; JButton keys[]=new JButton[KEYS.length]; JTextField text=new JTextField(50); double num1=0,num2=0; @@ -15,15 +15,16 @@ String b="+"; boolean root=false;//记录是否有过操作 public JSQ() { JFrame frame = new JFrame("Lia's caculator"); - frame.setBounds(10, 10, 400, 400); + frame.setBounds(8, 8, 420, 300); frame.setLayout(new BorderLayout()); text.setHorizontalAlignment(JTextField.RIGHT); JPanel pan1=new JPanel(); - pan1.setLayout(new GridLayout(5,5,10,10)); - pan1.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + pan1.setLayout(new GridLayout(5,5,8,8)); + pan1.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); for(int i=0;i Date: Sun, 29 May 2022 11:39:32 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=A4=96=E8=A7=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/java2022spring/JSQ.java | 35 ++++++++++++------- .../{LiaCaculator.java => LiaCalculator.java} | 6 ++-- 2 files changed, 25 insertions(+), 16 deletions(-) rename src/java2022spring/{LiaCaculator.java => LiaCalculator.java} (73%) diff --git a/src/java2022spring/JSQ.java b/src/java2022spring/JSQ.java index e8af34b..af14355 100644 --- a/src/java2022spring/JSQ.java +++ b/src/java2022spring/JSQ.java @@ -14,17 +14,22 @@ String result_string; String b="+"; boolean root=false;//记录是否有过操作 public JSQ() { - JFrame frame = new JFrame("Lia's caculator"); + JFrame frame = new JFrame("Lia's calculator"); frame.setBounds(8, 8, 420, 300); frame.setLayout(new BorderLayout()); text.setHorizontalAlignment(JTextField.RIGHT); + text.setBackground(new Color(221,221,221)); + text.setForeground(Color.blue); JPanel pan1=new JPanel(); - pan1.setLayout(new GridLayout(5,5,8,8)); + pan1.setLayout(new GridLayout(5,5,8,8));; + pan1.setBackground(Color.white); pan1.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); for(int i=0;i