韩佳杰 4 years ago
parent 0ebaba733a
commit a233a00cba

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-12">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>计算器窗体</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=12
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=12
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=12

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,31 @@
public class Calculate {
public String st;
public double CL(String st) {
Call call = new Call();
char[] cs = st.toCharArray();
int a = cs.length;
System.out.println(a);
double Temp = 0;
if(cs[0] == 'e') {
return call.e(cs[1]);
}
else if(cs[0] == 'l') {
return call.log(cs[1], cs[2]);
}
else if(cs[0] == 's' || cs[0] == 't' || cs[0] == 'c') {
for(int i=a-1;i>=3;i--) {
String s = String.valueOf(cs[i]);
int b = Integer.parseInt(s);
Temp = Temp + Math.pow(10,a-1-i)*b;
}
System.out.print(Temp);
return call.Trigonometric_Functions(cs[0], Temp);
}
else {
int num1 = Integer.parseInt(String.valueOf(cs[0]));
int num2 = Integer.parseInt(String.valueOf(cs[2]));
return call.jjcc(num1, num2, cs[1]);
}
}
}

@ -0,0 +1,205 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculater extends JFrame implements ActionListener {
private JPanel jPanel;
private JPanel jPanel1;
private Button button[] = new Button[24];
private TextField TF;
private String st = "";
private JScrollPane jscrollPane;
private JLabel label;
public void Define() {
JFrame jFrame = new JFrame("¼ÆËãÆ÷");
Container pane = jFrame.getContentPane();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jPanel = new JPanel(new GridLayout(6,4,5,5));
jPanel1 = new JPanel(new GridLayout(2,1,5,5));
TF = new TextField(st);
button[0] = new Button("sin");
button[0].addActionListener(this);
button[1] = new Button("cos");
button[1].addActionListener(this);
button[2] = new Button("tan");
button[2].addActionListener(this);
button[3] = new Button("e^x");
button[3].addActionListener(this);
button[4] = new Button("c");
button[4].addActionListener(this);
button[5] = new Button("¡Â");
button[5].addActionListener(this);
button[6] = new Button("¡Á");
button[6].addActionListener(this);
button[7] = new Button("<-");
button[7].addActionListener(this);
button[8] = new Button("7");
button[8].addActionListener(this);
button[9] = new Button("8");
button[9].addActionListener(this);
button[10] = new Button("9");
button[10].addActionListener(this);
button[11] = new Button("-");
button[11].addActionListener(this);
button[12] = new Button("4");
button[12].addActionListener(this);
button[13] = new Button("5");
button[13].addActionListener(this);
button[14] = new Button("6");
button[14].addActionListener(this);
button[15] = new Button("+");
button[15].addActionListener(this);
button[16] = new Button("1");
button[16].addActionListener(this);
button[17] = new Button("2");
button[17].addActionListener(this);
button[18] = new Button("3");
button[18].addActionListener(this);
button[19] = new Button("log");
button[19].addActionListener(this);
button[20] = new Button("%");
button[20].addActionListener(this);
button[21] = new Button("0");
button[21].addActionListener(this);
button[22] = new Button(".");
button[22].addActionListener(this);
button[23] = new Button("=");
button[23].addActionListener(this);
jPanel.add(button[0]);
jPanel.add(button[1]);
jPanel.add(button[2]);
jPanel.add(button[3]);
jPanel.add(button[4]);
jPanel.add(button[5]);
jPanel.add(button[6]);
jPanel.add(button[7]);
jPanel.add(button[8]);
jPanel.add(button[9]);
jPanel.add(button[10]);
jPanel.add(button[11]);
jPanel.add(button[12]);
jPanel.add(button[13]);
jPanel.add(button[14]);
jPanel.add(button[15]);
jPanel.add(button[16]);
jPanel.add(button[17]);
jPanel.add(button[18]);
jPanel.add(button[19]);
jPanel.add(button[20]);
jPanel.add(button[21]);
jPanel.add(button[22]);
jPanel.add(button[23]);
jPanel1.add(TF);
jPanel1.add(jPanel);
jscrollPane = new JScrollPane(label,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
pane.add(jPanel1,BorderLayout.WEST);
pane.add(jscrollPane,BorderLayout.EAST);
jFrame.pack();
jFrame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getActionCommand() == "0") {
st = st + "0";
this.TF.setText(st);
}
if(e.getActionCommand() == "1") {
st = st + "1";
this.TF.setText(st);
}
if(e.getActionCommand() == "2") {
st = st + "2";
this.TF.setText(st);
}
if(e.getActionCommand() == "3") {
st = st + "3";
this.TF.setText(st);
}
if(e.getActionCommand() == "4") {
st = st + "4";
this.TF.setText(st);
}
if(e.getActionCommand() == "5") {
st = st + "5";
this.TF.setText(st);
}
if(e.getActionCommand() == "6") {
st = st + "6";
this.TF.setText(st);
}
if(e.getActionCommand() == "7") {
st = st + "7";
this.TF.setText(st);
}
if(e.getActionCommand() == "8") {
st = st + "8";
this.TF.setText(st);
}
if(e.getActionCommand() == "9") {
st = st + "9";
this.TF.setText(st);
}
if(e.getActionCommand() == ".") {
st = st + ".";
this.TF.setText(st);
}
if(e.getActionCommand() == "+") {
st = st + "+";
this.TF.setText(st);
}
if(e.getActionCommand() == "-") {
st = st + "-";
this.TF.setText(st);
}
if(e.getActionCommand() == "¡Á") {
st = st + "¡Á";
this.TF.setText(st);
}
if(e.getActionCommand() == "¡Â") {
st = st + "¡Â";
this.TF.setText(st);
}
if(e.getActionCommand() == "sin") {
st = st + "sin";
this.TF.setText(st);
}
if(e.getActionCommand() == "cos") {
st = st + "cos";
this.TF.setText(st);
}
if(e.getActionCommand() == "tan") {
st = st + "tan";
this.TF.setText(st);
}
if(e.getActionCommand() == "%") {
st = st + "%";
this.TF.setText(st);
}
if(e.getActionCommand() == "e^x") {
st = st + "e^";
this.TF.setText(st);
}
if(e.getActionCommand() == "log") {
st = st + "log";
this.TF.setText(st);
}
if(e.getActionCommand() == "c") {
st = "";
this.TF.setText(st);
}
if(e.getActionCommand() == "=") {
Calculate CA = new Calculate();
double a = CA.CL(st);
st = String.valueOf((int)a);
this.TF.setText(st);
}
}
public static void main(String arg[]) {
Calculater A = new Calculater();
A.Define();
}
}

@ -0,0 +1,41 @@
public class Call {
static double jjcc(int a, int b,char chose) {
switch(chose) {
case '+':
return a+b;
case '-':
return a-b;
case '¡Á':
return a*b;
case '¡Â':
return a/b;
}
return 0;
}
static double e(int x) {
double e=Math.E;
double result;
result=Math.pow(e,x);
return result;
}
static double log(int a, int x) {
return Math.log(x)/Math.log(a);
}
static double Trigonometric_Functions(char chose,double Value) {
double a = Math.toRadians(Value);
switch(chose) {
case 's':
return Math.sin(a);
case 'c':
return Math.cos(a);
case 't':
return Math.tan(a);
}
return 0;
}
}
Loading…
Cancel
Save