From 12bac584d08fa6431c745353d9be08bc2848565b Mon Sep 17 00:00:00 2001 From: swingtilltheendofline <10959292+swingtilltheendofline@user.noreply.gitee.com> Date: Tue, 24 May 2022 01:30:02 +0000 Subject: [PATCH 01/11] add LICENSE. --- LICENSE | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ee58399 --- /dev/null +++ b/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. -- Gitee From b23d3154ed76b09f30343f64293304b9d5dd1eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Tue, 24 May 2022 22:16:22 +0800 Subject: [PATCH 02/11] init --- eclipse.exe.lnk | Bin 0 -> 891 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 eclipse.exe.lnk diff --git a/eclipse.exe.lnk b/eclipse.exe.lnk new file mode 100644 index 0000000000000000000000000000000000000000..06bea495e54de4af13600bf0d76e5e17ea70a863 GIT binary patch literal 891 zcmeZaU|?VrVFHp23LePBFLqND_MXfH{2`;Ni7Dm zVxVr*El<)-&eJtAFf!CNG=hnOUChACpa%>r>`qZyQh@tDn7kCK}hcAc# z(jbtNSWuE*pqrYWk#13xn!@m=t60E!-(HuVujbcJsfMaPu}t51Y|$IReakG`ucli5 zCM53)G?SBoVSy!(HVh63-YAyqvbMLtW4VWe-V)o29$BC`C;)-+1Ppx+v5E30I=%J^ OY5Keg-S`nC4g&ywQNEb~ literal 0 HcmV?d00001 -- Gitee From dd963724b4c537c8f8ac122363cd2b32c9bc282c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Wed, 25 May 2022 11:47:53 +0800 Subject: [PATCH 03/11] first commit --- src/{java2022spring => java2022springCalculator}/Test.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{java2022spring => java2022springCalculator}/Test.java (100%) diff --git a/src/java2022spring/Test.java b/src/java2022springCalculator/Test.java similarity index 100% rename from src/java2022spring/Test.java rename to src/java2022springCalculator/Test.java -- Gitee From 77b39be037f0697e336cbfa73a2490dd14f07da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Wed, 25 May 2022 17:02:57 +0800 Subject: [PATCH 04/11] =?UTF-8?q?third=20commit=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nonono git commit --- .../StandardCalculator.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/java2022springCalculator/StandardCalculator.java diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java new file mode 100644 index 0000000..a9751a5 --- /dev/null +++ b/src/java2022springCalculator/StandardCalculator.java @@ -0,0 +1,63 @@ +package java2022springCalculator; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.event.ActionListener; + +import javax.swing.*; +public class StandardCalculator extends JPanel{ + public static void main(String args[]) { + public Graphics g; + private static void calculatorFrame() { + JFrame frame1=new JFrame("׼");//һҳ + FlowLayout f1=new FlowLayout(FlowLayout.CENTER,10,10); + frame1.setLayout(f1); + frame1.setSize(270,550); + frame1.setLocationRelativeTo(null); + frame1.setDefaultCloseOperation(3); + JTextArea note=new JTextArea();//ı + note.setPreferredSize(new Dimension(250,200)); + note.setRows(3);//ı + frame1.add(note); + NoteListener notelistener =new NoteListener(); + notelistener.setJText(note); + String btArray[]={"1","2","3","+","4","5","6","-","7","8","9","*",".","0","=","/"};//ť + this.add(this); + frame1.add(this); + for(int i=0;i Date: Thu, 26 May 2022 23:44:26 +0800 Subject: [PATCH 05/11] four add a fil --- src/java2022springCalculator/MainClass.java | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/java2022springCalculator/MainClass.java diff --git a/src/java2022springCalculator/MainClass.java b/src/java2022springCalculator/MainClass.java new file mode 100644 index 0000000..327f965 --- /dev/null +++ b/src/java2022springCalculator/MainClass.java @@ -0,0 +1,31 @@ +package java2022springCalculator; +import javax.swing.*; +import javax.swing.event.*; +import java.awt.*; +public class MainClass extends JFrame implements ChangeListener{ + JTabbedPane Tab=new JTabbedPane(JTabbedPane.TOP); + StandardCalculator card1=new StandardCalculator(); + public void init() { + Tab.add("׼",card1); + this.add(Tab,BorderLayout.CENTER); + Tab.addChangeListener(this); + } + MainClass(){ + init(); + this.setTitle(""); + this.setBounds(200,200,400,400); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setVisible(true); + } + public void stateChanged(ChangeEvent arg0) { + if(Tab.getSelectedIndex()==0) { + Tab.setEnabledAt(0,true); + } + else if(Tab.getSelectedIndex()==1) { + Tab.setEnabledAt(1, true); + } + } + public static void main(String args[]) { + new MainClass(); +} + } -- Gitee From 69e53fc157f33b79d37062f0d10b822b1b43d348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Sat, 4 Jun 2022 22:54:35 +0800 Subject: [PATCH 06/11] 7 start over --- src/java2022springCalculator/MainClass.java | 31 --- .../StandardCalculator.java | 202 +++++++++++++----- src/java2022springCalculator/Test.java | 7 - 3 files changed, 144 insertions(+), 96 deletions(-) delete mode 100644 src/java2022springCalculator/MainClass.java delete mode 100644 src/java2022springCalculator/Test.java diff --git a/src/java2022springCalculator/MainClass.java b/src/java2022springCalculator/MainClass.java deleted file mode 100644 index 327f965..0000000 --- a/src/java2022springCalculator/MainClass.java +++ /dev/null @@ -1,31 +0,0 @@ -package java2022springCalculator; -import javax.swing.*; -import javax.swing.event.*; -import java.awt.*; -public class MainClass extends JFrame implements ChangeListener{ - JTabbedPane Tab=new JTabbedPane(JTabbedPane.TOP); - StandardCalculator card1=new StandardCalculator(); - public void init() { - Tab.add("׼",card1); - this.add(Tab,BorderLayout.CENTER); - Tab.addChangeListener(this); - } - MainClass(){ - init(); - this.setTitle(""); - this.setBounds(200,200,400,400); - this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - this.setVisible(true); - } - public void stateChanged(ChangeEvent arg0) { - if(Tab.getSelectedIndex()==0) { - Tab.setEnabledAt(0,true); - } - else if(Tab.getSelectedIndex()==1) { - Tab.setEnabledAt(1, true); - } - } - public static void main(String args[]) { - new MainClass(); -} - } diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index a9751a5..d3e3ebb 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -1,63 +1,149 @@ package java2022springCalculator; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.event.ActionListener; - +import java.awt.*; +import java.awt.event.*; import javax.swing.*; -public class StandardCalculator extends JPanel{ - public static void main(String args[]) { - public Graphics g; - private static void calculatorFrame() { - JFrame frame1=new JFrame("׼");//һҳ - FlowLayout f1=new FlowLayout(FlowLayout.CENTER,10,10); - frame1.setLayout(f1); - frame1.setSize(270,550); - frame1.setLocationRelativeTo(null); - frame1.setDefaultCloseOperation(3); - JTextArea note=new JTextArea();//ı - note.setPreferredSize(new Dimension(250,200)); - note.setRows(3);//ı - frame1.add(note); - NoteListener notelistener =new NoteListener(); - notelistener.setJText(note); - String btArray[]={"1","2","3","+","4","5","6","-","7","8","9","*",".","0","=","/"};//ť - this.add(this); - frame1.add(this); - for(int i=0;i Date: Sun, 5 Jun 2022 09:44:31 +0800 Subject: [PATCH 07/11] 8 changing the color of buttons --- .../StandardCalculator.java | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index d3e3ebb..fa90e90 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -51,7 +51,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL tf1=new JTextField(""); jp.add(tf1);//ı tf1.setEnabled(false);//ıť޷ - tf1.setBounds(0, 0, 200, 34);//λ + tf1.setBounds(0, 0, 200, 28);//λ tf1.setHorizontalAlignment(JLabel.RIGHT);//ñǩݰָʽ tf1.setFont(new Font("",Font.PLAIN,12)); tf1.setDisabledTextColor(Color.BLACK);//ɫ @@ -60,7 +60,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL tf2=new JTextField("0");//ΪʼֵΪ0 jp.add(tf2); tf2.setEnabled(false); - tf2.setBounds(20, 20, 180, 34);//λúʹСֵһ£tf3Ҳ + tf2.setBounds(20, 28, 180, 34);//λúʹСֵһ£tf3Ҳ tf2.setHorizontalAlignment(JLabel.RIGHT); tf2.setFont(new Font("",Font.BOLD,20)); tf2.setDisabledTextColor(Color.BLACK); @@ -69,7 +69,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL tf3=new JTextField(""); jp.add(tf3); tf3.setEnabled(false); - tf3.setBounds(0, 20, 30, 34); + tf3.setBounds(0, 28, 30, 34); tf3.setHorizontalAlignment(JLabel.CENTER); tf3.setFont(new Font("",Font.PLAIN,20)); tf3.setDisabledTextColor(Color.BLACK); @@ -80,36 +80,77 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL //ַ飬ѭķʽӰӱ int i; button=new JButton[28];//һ28 - for(i=0;i<24;i++)//ѭ + for(i=0;i<8;i++)//ѭ //ѭοԴhttps://blog.csdn.net/mitongxue/article/details/90489434 { button[i]=new JButton(buttonname[i]);//ּӵλ button[i].setFont(new Font("",Font.PLAIN,25));//ʹС - button[i].setForeground(Color.PINK);//ɫ + button[i].setForeground(Color.RED);//水úɫ + button[i].setBackground(Color.WHITE);//ɫ button[i].setMargin(new java.awt.Insets(0,0,0,0)); - button[i].setBounds(i%5*(35+20+15), 60+i/5*(29+10+15)+5, 50, 50);//ðλúʹС + button[i].setBounds(i%5*70, 60+i/5*54+5, 50, 50);//ðλúʹС jp.add(button[i]);//뵽 } + for(i=8;i<24;i++) + { + if(i==8||i==9||i==13||i==14||i==18||i==19||i==23) { + button[i]=new JButton(buttonname[i]);//ּӵλ + button[i].setFont(new Font("",Font.PLAIN,25));//ʹС + button[i].setForeground(Color.BLUE);//ɫ + button[i].setBackground(Color.WHITE);//ɫ + button[i].setMargin(new java.awt.Insets(0,0,0,0)); + button[i].setBounds(i%5*70, 60+i/5*54+5, 50, 50);//ðλúʹС + jp.add(button[i]);//뵽 + } + else { + button[i]=new JButton(buttonname[i]); + button[i].setFont(new Font("",Font.PLAIN,25)); + button[i].setForeground(Color.PINK);//ְ÷ɫ + button[i].setBackground(Color.WHITE);//ɫ + button[i].setMargin(new java.awt.Insets(0,0,0,0)); + button[i].setBounds(i%5*70, 60+i/5*54+5, 50, 50); + jp.add(button[i]); + } + } button[i]=new JButton(buttonname[i]);//ΪۣȺŰӳ button[i].setFont(new Font("",Font.PLAIN,25)); + button[i].setForeground(Color.BLUE);//ɫ + button[i].setBackground(Color.WHITE);//ɫ button[i].setMargin(new java.awt.Insets(0,0,0,0)); - button[i].setBounds(i%5*(35+20+15), 60+i/5*(29+10+15)+5, 50, 50*2+5); + button[i].setBounds(i%5*70, 60+i/5*54+5, 50, 50*2+5); jp.add(button[i]);//ϰ i++; button[i]=new JButton(buttonname[i]);//Ϊۣ0Ű button[i].setFont(new Font("",Font.PLAIN,25)); + button[i].setForeground(Color.PINK);//ְ÷ɫ + button[i].setBackground(Color.WHITE);//ɫ button[i].setMargin(new java.awt.Insets(0,0,0,0)); - button[i].setBounds(i%5*(35+20+15), 60+i/5*(29+10+15)+5, 50*2+20, 50); + button[i].setBounds(i%5*70, 60+i/5*54+5, 50*2+20, 50); jp.add(button[i]);//ϰ for(i=i+1;i Date: Sun, 5 Jun 2022 10:48:42 +0800 Subject: [PATCH 08/11] 9 create some methods --- .../StandardCalculator.java | 82 ++++++++++++++++++- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index fa90e90..1e4467a 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -10,6 +10,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL private JButton button[];//찴 private Dialog dialog; private Label dlabel; + private boolean Disable=false; public static void main(String[] args) {// StandardCalculator sc=new StandardCalculator(); @@ -147,7 +148,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL jp.add(tf3); this.add(jp); this.setVisible(true); - this.addWindowListener(new WinClose());//עᴰڼ + this.addWindowListener(new Window());//עᴰڼ this.setVisible( true ); } @@ -183,10 +184,83 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL } } - - - } + class mouse extends MouseAdapter{ + public void mouseClicked(MouseEvent e)// + { + JButton button=(JButton)e.getSource(); + if(Disable)//ðťC ָ + { + if(button.getText()=="C") + { clear(); + Disable=false; + } + else + return; + } + switch(button.getText()) //гѡ񰴼 + { + case "MC":mc();break;//ԴӦķ + case "MR":mr();break; + case "MS":ms();break; + case "M+":mAdd();break; + case "M-":mCut();break; + case "":tuiwei();break; + case "CE":qingchu();break; + case "C":clear();break; + case "":zhengfu();break; + case "":sqrt();break; + case "7": + case "8": + case "9": + case "4": + case "5": + case "6": + case "3": + case "2": + case "1"://һ + case "0":read(Integer.parseInt(button.getText()));break;//ϵıתΪInt + case "/":chufa();break; + case "%":qiuyu();break; + case "*":chengfa();break; + case "1/x":fenshu();break; + case "-":jianfa();break; + case "+":jiafa();break; + case "=":dengyu();break; + case ".":dian();break; + } + } + public void mouseEntered(MouseEvent e) + { + ((JButton)e.getSource()).setBackground(Color.white); + } + } + public void windowOpened(WindowEvent e){}//ʵwindow + public void windowActivated(WindowEvent e){} + public void windowDeactivated(WindowEvent e){} + public void windowClosed(WindowEvent e){} + public void windowIconified(WindowEvent e){} + public void windowDeiconified(WindowEvent e){} + public void windowClosing(WindowEvent e){ + if(e.getSource()==dialog) + dialog.setVisible(false); + else + System.exit(0); + } +} +class Window implements WindowListener +{//Ӧο룺https://blog.csdn.net/u010142437/article/details/8914348 + public void windowClosing(WindowEvent e)//ڹرհťʱִʵִڼӿеķ + { + System.exit(0);// + } + public void windowOpened(WindowEvent e){} + public void windowActivated(WindowEvent e){} + public void windowDeactivated(WindowEvent e){} + public void windowClosed(WindowEvent e){} + public void windowIconified(WindowEvent e){} + public void windowDeiconified( WindowEvent e){} +} -- Gitee From 244f86e9513023c19aa71e4ad3e29954c7a88f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Sun, 5 Jun 2022 13:32:06 +0800 Subject: [PATCH 09/11] 9 add some mothods --- .../StandardCalculator.java | 84 ++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index 1e4467a..6bdefa6 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -11,6 +11,10 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL private Dialog dialog; private Label dlabel; private boolean Disable=false; + private chuCun chucun=new chuCun();// + private bNumber n1=new bNumber(),n2=new bNumber();//ֱԱжֵļ + private String action="n1";//n1ΪҪĶn2ͬ + private String s1,s2;//ַô public static void main(String[] args) {// StandardCalculator sc=new StandardCalculator(); @@ -234,18 +238,94 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL ((JButton)e.getSource()).setBackground(Color.white); } } + + class bNumber {//һ + public double value;//ʵֵ + public int xiaoShuWei;//С,¼Сλ + public String xiaoShuString;//1/xַ + public String sqrtString;//sqrtַ + public boolean isSqrt,isFenShu;//жǷ񿪷߱ɷ + public boolean clear;//жǷ˽ + public boolean isXiaoShu;//жǷСǣture + public bNumber() + { + value=0;//óʼֵ + xiaoShuWei=0; + sqrtString=null; + xiaoShuString=null; + isSqrt=false; + isFenShu=false; + clear=false; + isXiaoShu=false; + } + public void chongZhi()// + { + value=0;//Ƴʼֵ + xiaoShuWei=0; + sqrtString=null; + xiaoShuString=null; + isSqrt=false; + isFenShu=false; + clear=false; + isXiaoShu=false; + } + } + class chuCun{//洢 + public double cNumber;//洢洢 + public boolean cStart;//Ƿ洢 + public chuCun() + { + cNumber=0;//óʼֵΪ㣬û + cStart=false; + } + } + + public void mc()//MCȡ + { + chucun.cNumber=0;//ôֵ + chucun.cStart=false; + tf3.setText(null); + } + + public void mr()//MRȡϴ + { + n1.value=chucun.cNumber; + s2=""+n1.value; + if(n1.value==Math.floor(n1.value)) + s2=""+(int)n1.value; + tf2.setText(s2); + n1.clear=true; + } + + public void ms()// + { + chucun.cNumber=n1.value; + tf3.setText("M");//ϽʾM־ + } + + public void mAdd()//m+:ӵǰʹ洢 + { + chucun.cNumber=chucun.cNumber+n1.value; + } + + public void mCut()//M-:ǰ洢 + { + chucun.cNumber=chucun.cNumber-n1.value; + } + public void windowOpened(WindowEvent e){}//ʵwindow public void windowActivated(WindowEvent e){} public void windowDeactivated(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){} - public void windowClosing(WindowEvent e){ + public void windowClosing(WindowEvent e) + { if(e.getSource()==dialog) dialog.setVisible(false); else System.exit(0); - } + } } class Window implements WindowListener -- Gitee From 03cd5e0f83cb36543d8e91359e5b5f18ad1e1896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Sun, 5 Jun 2022 16:20:30 +0800 Subject: [PATCH 10/11] 9 write some metods --- .../StandardCalculator.java | 112 +++++++++++++++--- 1 file changed, 94 insertions(+), 18 deletions(-) diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index 6bdefa6..5cb6008 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -1,9 +1,9 @@ package java2022springCalculator; import java.awt.*; import java.awt.event.*; +import java.math.BigDecimal; import javax.swing.*; import javax.swing.border.LineBorder; - public class StandardCalculator extends JFrame implements ActionListener,WindowListener{ private JTextField tf1,tf2,tf3;//ıtf1棬tf2㣬tf3ʾMS private String buttonname[]={"MC","MR","MS","M+","M-","","CE","C","","","7","8","9","/","%","4","5","6","*","1/x","1","2","3","-","=","0",".","+"};//ְ˳ź @@ -15,11 +15,10 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL private bNumber n1=new bNumber(),n2=new bNumber();//ֱԱжֵļ private String action="n1";//n1ΪҪĶn2ͬ private String s1,s2;//ַô - + private String fuhao="";//ţʼΪյ public static void main(String[] args) {// StandardCalculator sc=new StandardCalculator(); } - public StandardCalculator()//ý { super("׼"); @@ -48,7 +47,6 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); tf1=new JTextField(30);// final StandardCalculator a = this; - JPanel jp=new JPanel(null);//ʾ jp.setBounds(10,15,getWidth()-24,getHeight());//λС jp.setBackground(Color.WHITE);//ɫ @@ -80,8 +78,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL tf3.setDisabledTextColor(Color.BLACK); tf3.setBorder(new LineBorder(new Color(242,247,252))); tf3.setBackground(new Color(242,247,252)); - this.add(jp);//󣬽ײ - + this.add(jp);//󣬽ײ //ַ飬ѭķʽӰӱ int i; button=new JButton[28];//һ28 @@ -155,7 +152,6 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL this.addWindowListener(new Window());//עᴰڼ this.setVisible( true ); } - public void actionPerformed(ActionEvent e) //ڽת¼ӦԼ˵ { if(e.getActionCommand()=="")//Ƶת @@ -187,7 +183,6 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL } } - class mouse extends MouseAdapter{ public void mouseClicked(MouseEvent e)// { @@ -238,7 +233,6 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL ((JButton)e.getSource()).setBackground(Color.white); } } - class bNumber {//һ public double value;//ʵֵ public int xiaoShuWei;//С,¼Сλ @@ -279,14 +273,12 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL cStart=false; } } - public void mc()//MCȡ { chucun.cNumber=0;//ôֵ chucun.cStart=false; tf3.setText(null); } - public void mr()//MRȡϴ { n1.value=chucun.cNumber; @@ -296,22 +288,109 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL tf2.setText(s2); n1.clear=true; } - public void ms()// { chucun.cNumber=n1.value; tf3.setText("M");//ϽʾM־ } - public void mAdd()//m+:ӵǰʹ洢 { chucun.cNumber=chucun.cNumber+n1.value; } - public void mCut()//M-:ǰ洢 { chucun.cNumber=chucun.cNumber-n1.value; } + public void tuiwei()//ȥһλ֣ο룺https://blog.csdn.net/qq_44716544/article/details/100863984 + { + if(action=="n1"&&n1.value!=0)//㲻0n1 + { + if(n1.isXiaoShu==false)//n1Ϊ + { + n1.value=(int)n1.value/10; + s2=""+(int)n1.value;//s2n1ļ + } + else{//n1ΪС + BigDecimal bd=new BigDecimal(n1.value); + n1.value=bd.setScale(--n1.xiaoShuWei,BigDecimal.ROUND_DOWN).doubleValue(); + s2=""+n1.value; + if(n1.xiaoShuWei==0)//Сλȥ + n1.isXiaoShu=false;//isXiaoShuΪfalse + } + } + else if(action=="n2"&&n2.value!=0)//ʾn2вn1 + { + if(n2.isXiaoShu==false)//n2λ + { + n2.value=(int)n2.value/10; + s2=""+(int)n2.value; + } + else{//n2ΪС + BigDecimal bd=new BigDecimal(n2.value);//ԶλСоȷ + n2.value=bd.setScale(--n2.xiaoShuWei,BigDecimal.ROUND_DOWN ).doubleValue(); + s2=""+n2.value; + if(n2.xiaoShuWei==0) + n2.isXiaoShu=false; + } + } + tf2.setText(s2);//޸ĺIJ + } + public void qingchu()//CE + { + if(action=="n1") + n1.chongZhi();//bNumberchongZhi + else if(action=="n2") + n2.chongZhi(); + tf2.setText("0");//ʼʾ2 + } + public void clear()//C:ü + { + n1.chongZhi(); + n2.chongZhi(); + action="n1"; + fuhao=""; + tf1.setText("");//ʾ + tf2.setText("0"); + } + public void zhengfu()// + { + if(action=="n1") + { + n1.value=-n1.value; + s2=""+n1.value; + } + else if(action=="n2") + { + n2.value=-n2.value; + s2=""+n2.value; + } + tf2.setText(s2); + } + public void sqrt()//,οԴhttps://blog.csdn.net/qq_44716544/article/details/100863984 + { + double x;//һʱ + if(action=="n1") + { + n1.sqrtString="sqrt("+n1.value+")"; + n1.value=Math.sqrt(n1.value); + n1.isSqrt=true; + x=n1.value; + } + else + { + n2.sqrtString="sqrt("+n2.value+")"; + n2.value=Math.sqrt(n2.value); + n2.isSqrt=true; + x=n2.value; + } + s2=x+""; + if(x==Math.floor(x))//xΪ + { + s2=(int)x+"";//xתΪintתַ + } + tf2.setText(s2); + } + public void windowOpened(WindowEvent e){}//ʵwindow public void windowActivated(WindowEvent e){} @@ -340,7 +419,4 @@ class Window implements WindowListener public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified( WindowEvent e){} -} - - - +} \ No newline at end of file -- Gitee From 87ea3b41f6c31ecbfcd3334ad3eafdad290049cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=81=E9=95=9C?= <1583993890@qq.com> Date: Sun, 5 Jun 2022 21:33:16 +0800 Subject: [PATCH 11/11] 10 finish --- .../StandardCalculator.java | 271 +++++++++++++++++- 1 file changed, 259 insertions(+), 12 deletions(-) diff --git a/src/java2022springCalculator/StandardCalculator.java b/src/java2022springCalculator/StandardCalculator.java index 5cb6008..ce937f9 100644 --- a/src/java2022springCalculator/StandardCalculator.java +++ b/src/java2022springCalculator/StandardCalculator.java @@ -15,7 +15,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL private bNumber n1=new bNumber(),n2=new bNumber();//ֱԱжֵļ private String action="n1";//n1ΪҪĶn2ͬ private String s1,s2;//ַô - private String fuhao="";//ţʼΪյ + private String sign="";//ţʼΪյ public static void main(String[] args) {// StandardCalculator sc=new StandardCalculator(); } @@ -140,6 +140,7 @@ public class StandardCalculator extends JFrame implements ActionListener,WindowL jp.add(button[i]); } mouse m=new mouse();// + for(i=0;i=16)//Ļʾݵ󳤶 + { + tf2.setFont(new Font("",Font.BOLD,14));//С + tf2.setText(str.substring(0, 16)); + } + else + tf2.setText(str); + } + public void jianfa() + { + yunsuan("-"); + } + public void jiafa() + { + yunsuan("+"); + } + public void chufa() + { + yunsuan("/"); + } + public void qiuyu() + { + yunsuan("%"); + } + public void chengfa() + { + yunsuan("*"); + } + public void dengyu() + { + tf2.setFont(new Font("",Font.BOLD,20)); + int d1=n1.xiaoShuWei,d2=n2.xiaoShuWei,i; + switch(sign) + { //浽n1 + case "+":n1.value=n1.value+n2.value;break; + case "-":n1.value=n1.value-n2.value;break; + case "*":n1.value=n1.value*n2.value;break; + case "/":n1.value=n1.value/n2.value;break; + case "%":n1.value=n1.value%n2.value;break; + } + if(n2.value==0&&sign=="/")//Ϊ0 + { + Disable=true; + tf2.setText(n1.value+""); + tf1.setText(null); + action="n1"; + return ; + } + if(n1.value==Math.floor(n1.value))//Ϊ + { + tf2.setText((int)n1.value+""); + n1.xiaoShuWei=0; + n1.isXiaoShu=false; + } + else{//С + String str=n1.value+""; + if(sign.equals("+")||sign.equals("-")||sign.equals("%"))//ӼĴ + { + i=d1>d2?d1:d2;//ҪжִС + str=n1.value+""; + str=str.substring(0, str.indexOf(".")+i+1);//ȡiλ + } + else if(sign.equals("*")) + { + i=d1+d2; + BigDecimal bd=new BigDecimal(n1.value); + n1.value=bd.setScale(i,BigDecimal.ROUND_DOWN ).doubleValue(); + str=n1.value+"";//޸ĺstr + } + if(str.length()>=16)//ʾķΧ + { + tf2.setFont(new Font("",Font.BOLD,14)); + str=str.substring(0, 16); + } + tf2.setText(str); + n1.xiaoShuWei=str.length()-str.indexOf(".")-1;//µn1ֵ + } + tf1.setText(null); + action="n1"; + n1.clear=true;//n1ٿʼµļ + n2.clear=true; + sign="";// + } + public void dian() + { + if(action=="n1") + n1.isXiaoShu=true; + else + n2.isXiaoShu=true; + tf2.setText(tf2.getText()+"."); + } + public void yunsuan(String SIGN) + { + tf2.setFont(new Font("",Font.BOLD,20)); + action="n2"; + int d1=n1.xiaoShuWei,d2=n2.xiaoShuWei,i; + if(!sign.equals(""))//ǷDZʽĵһ + { + switch(sign)// + { + case "+":n1.value=n1.value+n2.value;break; + case "-":n1.value=n1.value-n2.value;break; + case "*":n1.value=n1.value*n2.value;break; + case "/":n1.value=n1.value/n2.value;break; + case "%":n1.value=n1.value%n2.value;break; + } + } + String temp=teshu(); + if(temp==null) + temp=tf2.getText();//ȱtf2ı + if(n2.value==0&&sign=="/")//Ϊ0 + { + Disable=true; + tf2.setText(n1.value+""); + tf1.setText(tf1.getText()+n1.value); + } + if(n1.value==Math.floor(n1.value))//Ϊ + { + tf2.setText((int)n1.value+""); + n1.xiaoShuWei=0; + n1.isXiaoShu=false; + } + else{ + String str=n1.value+""; + if(sign.equals("+")||sign.equals("-")||sign.equals("%")) + { + i=d1>d2?d1:d2; + BigDecimal bd=new BigDecimal(n1.value); + n1.value=bd.setScale(i,BigDecimal.ROUND_DOWN ).doubleValue(); + str=n1.value+"";//޸ĺstr + } + else if(sign.equals("*")) + { + i=d1+d2; + BigDecimal bd=new BigDecimal(n1.value); + n1.value=bd.setScale(i,BigDecimal.ROUND_DOWN ).doubleValue(); + str=n1.value+"";//޸ĺstr + } + if(str.length()>=16) + { + tf2.setFont(new Font("",Font.BOLD,14)); + str=str.substring(0, 16); + } + tf2.setText(str); + n1.xiaoShuWei=str.length()-str.indexOf(".")-1;//ÿμ,n1ֵΪС + } + sign=SIGN; + tf1.setText(tf1.getText()+temp+sign); + n2.value=n1.value;//󣬲n2ĬϵֵΪn1ֵ + n2.clear=true;//ɺ + n1.clear=false;//ͬ + } + public String teshu()//ο룺https://blog.csdn.net/qq_45067089/article/details/96458951 + { + String temp=null; + if(n1.isSqrt) + { + temp=n1.sqrtString; + n1.isSqrt=false; + } + else if(n2.isSqrt) + { + temp=n2.sqrtString; + n2.isSqrt=false; + } + if(n1.isFenShu) + { + temp=n1.fenShuString; + n1.isFenShu=false; + } + else if(n2.isFenShu) + { + temp=n2.fenShuString; + n2.isFenShu=false; + } + return temp; + } public void windowOpened(WindowEvent e){}//ʵwindow public void windowActivated(WindowEvent e){} -- Gitee