陈佳媛 2 months ago
commit 1fc5cbec40

3
.idea/.gitignore vendored

@ -0,0 +1,3 @@
# 默认忽略的文件
/shelf/
/workspace.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$/lesson2.iml" filepath="$PROJECT_DIR$/lesson2.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,11 +5,9 @@ import java.awt.event.ActionListener;
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
public class Calculator extends JFrame implements ActionListener {
private JTextField display;
private StringBuilder input;
public Calculator() {
input = new StringBuilder();
display = new JTextField();
@ -20,7 +18,6 @@ public class Calculator extends JFrame implements ActionListener {
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 4, 10, 10));
panel.setBackground(Color.GRAY);
String[] buttons = {
"7", "8", "9", "/",
"4", "5", "6", "*",
@ -36,7 +33,6 @@ public class Calculator extends JFrame implements ActionListener {
}
add(display, BorderLayout.NORTH);
add(panel, BorderLayout.CENTER);
setTitle("Calculator");
setSize(400, 500);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -62,12 +58,10 @@ public class Calculator extends JFrame implements ActionListener {
display.setText(input.toString());
}
}
private double evaluate(String expression) throws ScriptException {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
return ((Number) engine.eval(expression)).doubleValue();
}
//11122222
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
Calculator calculator = new Calculator();

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Loading…
Cancel
Save