diff --git a/src/System/out/production/System/CalculatorWindow.class b/src/System/out/production/System/CalculatorWindow.class new file mode 100644 index 0000000..d96fb96 Binary files /dev/null and b/src/System/out/production/System/CalculatorWindow.class differ diff --git a/src/System/out/production/System/Computer.class b/src/System/out/production/System/Computer.class new file mode 100644 index 0000000..1547526 Binary files /dev/null and b/src/System/out/production/System/Computer.class differ diff --git a/src/System/out/production/System/Fu.class b/src/System/out/production/System/Fu.class new file mode 100644 index 0000000..7e2096a Binary files /dev/null and b/src/System/out/production/System/Fu.class differ diff --git a/src/System/out/production/System/HandleBack.class b/src/System/out/production/System/HandleBack.class new file mode 100644 index 0000000..d44cb4b Binary files /dev/null and b/src/System/out/production/System/HandleBack.class differ diff --git a/src/System/out/production/System/HandleClear.class b/src/System/out/production/System/HandleClear.class new file mode 100644 index 0000000..72a2d99 Binary files /dev/null and b/src/System/out/production/System/HandleClear.class differ diff --git a/src/System/out/production/System/HandleDight.class b/src/System/out/production/System/HandleDight.class new file mode 100644 index 0000000..9db019e Binary files /dev/null and b/src/System/out/production/System/HandleDight.class differ diff --git a/src/System/out/production/System/HandleEquation.class b/src/System/out/production/System/HandleEquation.class new file mode 100644 index 0000000..d641b9d Binary files /dev/null and b/src/System/out/production/System/HandleEquation.class differ diff --git a/src/System/out/production/System/HandleEvent.class b/src/System/out/production/System/HandleEvent.class new file mode 100644 index 0000000..186e21e Binary files /dev/null and b/src/System/out/production/System/HandleEvent.class differ diff --git a/src/System/out/production/System/HandleFile.class b/src/System/out/production/System/HandleFile.class new file mode 100644 index 0000000..c9e0a99 Binary files /dev/null and b/src/System/out/production/System/HandleFile.class differ diff --git a/src/System/out/production/System/HandleFu.class b/src/System/out/production/System/HandleFu.class new file mode 100644 index 0000000..58231af Binary files /dev/null and b/src/System/out/production/System/HandleFu.class differ diff --git a/src/System/out/production/System/HandleOperator.class b/src/System/out/production/System/HandleOperator.class new file mode 100644 index 0000000..0dbdfbf Binary files /dev/null and b/src/System/out/production/System/HandleOperator.class differ diff --git a/src/System/out/production/System/HandleReciprocal.class b/src/System/out/production/System/HandleReciprocal.class new file mode 100644 index 0000000..6dedefd Binary files /dev/null and b/src/System/out/production/System/HandleReciprocal.class differ diff --git a/src/System/out/production/System/HandleSqrt.class b/src/System/out/production/System/HandleSqrt.class new file mode 100644 index 0000000..428a42c Binary files /dev/null and b/src/System/out/production/System/HandleSqrt.class differ diff --git a/src/System/out/production/System/MathComputer.class b/src/System/out/production/System/MathComputer.class new file mode 100644 index 0000000..4d82b93 Binary files /dev/null and b/src/System/out/production/System/MathComputer.class differ diff --git a/src/System/out/production/System/Reciprocal.class b/src/System/out/production/System/Reciprocal.class new file mode 100644 index 0000000..903963b Binary files /dev/null and b/src/System/out/production/System/Reciprocal.class differ diff --git a/src/System/out/production/System/Sqrt.class b/src/System/out/production/System/Sqrt.class new file mode 100644 index 0000000..9bde3d4 Binary files /dev/null and b/src/System/out/production/System/Sqrt.class differ diff --git a/src/System/out/production/System/test.class b/src/System/out/production/System/test.class new file mode 100644 index 0000000..b539448 Binary files /dev/null and b/src/System/out/production/System/test.class differ diff --git a/src/System/src/Fu.java b/src/System/src/Fu.java new file mode 100644 index 0000000..bf3fc3c --- /dev/null +++ b/src/System/src/Fu.java @@ -0,0 +1,14 @@ +public class Fu implements MathComputer{ + @Override + public void handle(Computer data) { + String s=""; + double r=data.computerDataItem(); + data.tempResult.push(r); + r=-r; + s=HandleEvent.get(r); + data.dataItem.removeAllElements(); + for (int i = 0; i < s.length(); i++) { + data.dataItem.push(s.charAt(i)); + } + } +} diff --git a/src/System/src/HandleBack.java b/src/System/src/HandleBack.java new file mode 100644 index 0000000..ec9e16a --- /dev/null +++ b/src/System/src/HandleBack.java @@ -0,0 +1,13 @@ +import java.awt.event.ActionEvent; + +public class HandleBack extends HandleEvent{ + public HandleBack(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + window.computer.backspace(); + show(); + } +} diff --git a/src/System/src/HandleClear.java b/src/System/src/HandleClear.java new file mode 100644 index 0000000..f1480f7 --- /dev/null +++ b/src/System/src/HandleClear.java @@ -0,0 +1,13 @@ +import java.awt.event.ActionEvent; + +public class HandleClear extends HandleEvent{ + public HandleClear(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + window.computer.init(); + show(); + } +} diff --git a/src/System/src/HandleDight.java b/src/System/src/HandleDight.java new file mode 100644 index 0000000..239dd69 --- /dev/null +++ b/src/System/src/HandleDight.java @@ -0,0 +1,21 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; + +public class HandleDight extends HandleEvent{ + public HandleDight(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + JButton b=(JButton) e.getSource(); + String btnName=b.getText().trim();//去除前后空白区 + char dight=btnName.charAt(0); + window.computer.setDataItem(dight); + show(); + if(dight=='.'){ + String s=get(window.computer.computerDataItem()); + window.showDataItem.setText(" "+s+"."); + } + } +} diff --git a/src/System/src/HandleEquation.java b/src/System/src/HandleEquation.java new file mode 100644 index 0000000..dbcb74e --- /dev/null +++ b/src/System/src/HandleEquation.java @@ -0,0 +1,23 @@ +import java.awt.event.ActionEvent; +public class HandleEquation extends HandleEvent{ + public HandleEquation(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + String s =""; + if(window.computer.computerDataItem()==window.computer.getResult()){ + if(window.computer.getTempResult()==-window.computer.getResult()) + s=" "+window.computer.getTempResult()+" 取反为 "+window.computer.getResult(); + if(1/window.computer.getTempResult()==window.computer.getResult()) + s=" "+window.computer.getTempResult()+" 倒数为 "+window.computer.getResult(); + if(Math.sqrt(window.computer.getTempResult())==window.computer.getResult()) + s=" "+window.computer.getTempResult()+" 开方为 "+window.computer.getResult(); + }else{ + s=" "+window.computer.getTempResult()+" "+window.computer.getOperator()+ + " "+window.computer.computerDataItem()+" = "+window.computer.getResult();} + window.computerProcess.append("\n"+s); +// show(); + } +} diff --git a/src/System/src/HandleEvent.java b/src/System/src/HandleEvent.java new file mode 100644 index 0000000..93b5e40 --- /dev/null +++ b/src/System/src/HandleEvent.java @@ -0,0 +1,31 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class HandleEvent implements ActionListener { + CalculatorWindow window; + + public HandleEvent(CalculatorWindow window) { + this.window = window; + } + public void show(){ + window.resultShow.setText(" = "+get(window.computer.getResult())); + window.showTempResult.setText(get(window.computer.getTempResult())+" "); + window.showOperator.setText(" "+window.computer.getOperator()+" "); + window.showDataItem.setText(" "+get(window.computer.computerDataItem())); + } + + public static String get(double r){//返回浮点数的串表示 + String s=""; + Double d=new Double(r); + long n=d.longValue();//得到r的整数部分 + if(Math.abs(r-n)>0)//取绝对值 + s=""+r; + else + s=""+n;//小数部分为0则省略 + return s; + } + + @Override + public void actionPerformed(ActionEvent e) { + } +} diff --git a/src/System/src/HandleFile.java b/src/System/src/HandleFile.java new file mode 100644 index 0000000..b7396b1 --- /dev/null +++ b/src/System/src/HandleFile.java @@ -0,0 +1,42 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.io.*; + +public class HandleFile extends HandleEvent{ + public HandleFile(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + if(e.getSource()==window.copyBtn){ + window.computerProcess.copy(); + } + if(e.getSource()==window.clearTextBtn){ + window.computerProcess.setText(null); + } + if(e.getSource()==window.saveBtn){ + JFileChooser chooser=new JFileChooser(); + int state=chooser.showSaveDialog(null); + File file =chooser.getSelectedFile(); + if(file!=null&&state==JFileChooser.APPROVE_OPTION){ + try { + String content=window.computerProcess.getText(); + StringReader reader=new StringReader(content); + BufferedReader in=new BufferedReader(reader); + FileWriter fw=new FileWriter(file); + BufferedWriter out=new BufferedWriter(fw); + String s=null; + while ((s=in.readLine())!=null){ + out.write(s); + out.newLine(); + } + in.close(); + out.close(); + }catch (IOException exception){ + + } + } + } + } +} diff --git a/src/System/src/HandleFu.java b/src/System/src/HandleFu.java new file mode 100644 index 0000000..3734bdd --- /dev/null +++ b/src/System/src/HandleFu.java @@ -0,0 +1,13 @@ +import java.awt.event.ActionEvent; + +public class HandleFu extends HandleEvent{ + public HandleFu(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + window.computer.initMath(new Fu()); + show(); + } +} diff --git a/src/System/src/HandleOperator.java b/src/System/src/HandleOperator.java new file mode 100644 index 0000000..93fc991 --- /dev/null +++ b/src/System/src/HandleOperator.java @@ -0,0 +1,18 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; + +public class HandleOperator extends HandleEvent{ + public HandleOperator(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + JButton b=(JButton) e.getSource(); + String btnName; + btnName=b.getText().trim();//去除前后空白区 + char operator=btnName.charAt(0); + window.computer.setOperator(operator); + show(); + } +} diff --git a/src/System/src/HandleReciprocal.java b/src/System/src/HandleReciprocal.java new file mode 100644 index 0000000..bdd79c7 --- /dev/null +++ b/src/System/src/HandleReciprocal.java @@ -0,0 +1,13 @@ +import java.awt.event.ActionEvent; + +public class HandleReciprocal extends HandleEvent{ + public HandleReciprocal(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + window.computer.initMath(new Reciprocal()); + show(); + } +} diff --git a/src/System/src/HandleSqrt.java b/src/System/src/HandleSqrt.java new file mode 100644 index 0000000..90b41a6 --- /dev/null +++ b/src/System/src/HandleSqrt.java @@ -0,0 +1,13 @@ +import java.awt.event.ActionEvent; + +public class HandleSqrt extends HandleEvent{ + public HandleSqrt(CalculatorWindow window) { + super(window); + } + + @Override + public void actionPerformed(ActionEvent e) { + window.computer.initMath(new Sqrt()); + show(); + } +} diff --git a/src/System/src/MathComputer.java b/src/System/src/MathComputer.java new file mode 100644 index 0000000..eb7c386 --- /dev/null +++ b/src/System/src/MathComputer.java @@ -0,0 +1,3 @@ +public interface MathComputer { + public void handle(Computer data); +} diff --git a/src/System/src/Reciprocal.java b/src/System/src/Reciprocal.java new file mode 100644 index 0000000..aa7ac7c --- /dev/null +++ b/src/System/src/Reciprocal.java @@ -0,0 +1,14 @@ +public class Reciprocal implements MathComputer{ + @Override + public void handle(Computer data) { + String s=""; + double r= data.computerDataItem(); + data.tempResult.push(r); + r=1/r; + s=HandleEvent.get(r); + data.dataItem.removeAllElements(); + for (int i = 0; i < s.length(); i++) { + data.dataItem.push(s.charAt(i)); + } + } +} diff --git a/src/System/src/Sqrt.java b/src/System/src/Sqrt.java new file mode 100644 index 0000000..8bc3585 --- /dev/null +++ b/src/System/src/Sqrt.java @@ -0,0 +1,15 @@ +public class Sqrt implements MathComputer{ + + @Override + public void handle(Computer data) { + String s=""; + double r=data.computerDataItem(); + data.tempResult.push(r); + r=Math.sqrt(r); + s=HandleEvent.get(r); + data.dataItem.removeAllElements(); + for (int i = 0; i < s.length(); i++) { + data.dataItem.push(s.charAt(i)); + } + } +} diff --git a/src/System/src/test.java b/src/System/src/test.java new file mode 100644 index 0000000..316503b --- /dev/null +++ b/src/System/src/test.java @@ -0,0 +1,5 @@ +public class test { + public static void main(String[] args) { + CalculatorWindow cw=new CalculatorWindow(); + } +} diff --git a/src/test.txt b/src/test.txt deleted file mode 100644 index 062779c..0000000 --- a/src/test.txt +++ /dev/null @@ -1 +0,0 @@ -测试git上传。。。 \ No newline at end of file