master
wjy 10 months ago
parent 402820b53a
commit 5ab1a14d9d

29
.gitignore vendored

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/Computer.iml" filepath="$PROJECT_DIR$/Computer.iml" />
</modules>
</component>
</project>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

@ -5,7 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

@ -6,34 +6,29 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.MessageFormat;
import java.util.Arrays;
public class a {
public class com {
public static void main(String[] args) {
new JS();
}
}
class JS extends JFrame implements ActionListener {
private final StringBuilder sBuilder = new StringBuilder();
JTextArea text = new JTextArea();
double a, b;
Double sum;
String lastOperator = "=";
public JS() {
setBounds(100, 100, 400, 400);
setTitle("计算器");
JMenuBar menubar = new JMenuBar();
this.setJMenuBar(menubar);
this.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
text.setPreferredSize(new Dimension(370, 60));
p2.setLayout(new FlowLayout());
p1.add(text);
this.add(p1, BorderLayout.NORTH);
p2.setLayout(new GridLayout(5, 4));
JButton[] button = new JButton[20];
button[0] = new JButton("C");
@ -56,17 +51,14 @@ class JS extends JFrame implements ActionListener {
button[17] = new JButton("0");
button[18] = new JButton(".");
button[19] = new JButton("=");
Arrays.stream(button).forEach(p2::add);
this.add(p2, BorderLayout.CENTER);
for (JButton jButton : button) {
jButton.addActionListener(this);
}
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {
String lab = e.getActionCommand();
@ -93,7 +85,6 @@ class JS extends JFrame implements ActionListener {
}
}
}
private void calculate() {
switch (lastOperator) {
case "+":
Loading…
Cancel
Save