Skip to content

Commit 0744f5a

Browse files
committed
first commit
1 parent b65cffb commit 0744f5a

File tree

7 files changed

+1366
-0
lines changed

7 files changed

+1366
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 COLORREF
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# calculator
2+
- Qt-C++普通计算器
3+
- Java普通、科学计算器

src/Calculator.java

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import counter.ScientificCalculator;
2+
import counter.StandardCalculator;
3+
4+
import javax.swing.JButton;
5+
import javax.swing.UnsupportedLookAndFeelException;
6+
7+
import java.awt.Font;
8+
import java.awt.event.ActionEvent;
9+
import java.awt.event.ActionListener;
10+
11+
public class Calculator implements ActionListener
12+
{
13+
StandardCalculator standard_calculator = new StandardCalculator();//标准计算器
14+
ScientificCalculator scientific_calculator = new ScientificCalculator();//科学计算器
15+
16+
private final JButton toggle_button_scientific = new JButton();//切换科学计算
17+
private final JButton toggle_button_standard = new JButton();//切换标准计算器
18+
19+
//窗口坐标
20+
private int x;
21+
private int y;
22+
private final int w = standard_calculator.getWidth();
23+
private final int h = standard_calculator.getHeight();
24+
25+
Calculator() throws
26+
UnsupportedLookAndFeelException,
27+
ClassNotFoundException,
28+
InstantiationException,
29+
IllegalAccessException {
30+
inItUi();
31+
}
32+
33+
private void inItUi() {
34+
toggle_button_scientific.setBounds(13, 0, 54, 30);
35+
toggle_button_scientific.setFocusPainted(false);
36+
toggle_button_scientific.setFocusable(false);
37+
toggle_button_scientific.setFont(new Font("微软雅黑", Font.PLAIN, 11));
38+
toggle_button_scientific.setText("科学");
39+
toggle_button_scientific.addActionListener(this);
40+
standard_calculator.getContentPane().add(toggle_button_scientific);
41+
42+
toggle_button_standard.setBounds(13, 0, 54, 30);
43+
toggle_button_standard.setFocusPainted(false);
44+
toggle_button_standard.setFocusable(false);
45+
toggle_button_standard.setFont(new Font("微软雅黑", Font.PLAIN, 11));
46+
toggle_button_standard.setText("标准");
47+
toggle_button_standard.addActionListener(this);
48+
scientific_calculator.getContentPane().add(toggle_button_standard);
49+
}
50+
51+
private void recordCoordinates(int x_, int y_) {
52+
x = x_;
53+
y = y_;
54+
}
55+
56+
public void exec(){
57+
standard_calculator.exec();
58+
scientific_calculator.exec();
59+
recordCoordinates(standard_calculator.getX(), standard_calculator.getY());
60+
scientific_calculator.setIsHidden(true);
61+
}
62+
63+
@Override
64+
public void actionPerformed(ActionEvent e) {
65+
String button_text = ((JButton) e.getSource()).getText();
66+
switch (button_text) {
67+
case "科学":
68+
recordCoordinates(standard_calculator.getX(), standard_calculator.getY());
69+
standard_calculator.setIsHidden(true);
70+
scientific_calculator.setBounds(x, y, w, h);
71+
scientific_calculator.setIsHidden(false);
72+
break;
73+
case "标准":
74+
recordCoordinates(scientific_calculator.getX(), scientific_calculator.getY());
75+
scientific_calculator.setIsHidden(true);
76+
standard_calculator.setBounds(x, y, w, h);
77+
standard_calculator.setIsHidden(false);
78+
break;
79+
}
80+
}
81+
}

src/Main.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import javax.swing.UnsupportedLookAndFeelException;
2+
3+
public class Main
4+
{
5+
public static void main(String[] arg) throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException
6+
{
7+
Calculator calculator = new Calculator();
8+
calculator.exec();
9+
}
10+
}

0 commit comments

Comments
 (0)