decred算力计算器
『壹』 (Java)谁有计算器的完整代码
真是爽阿,两个要这个代码的
看看我写得把,还不错,楼主给我追加点分吧
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Calculator extends JFrame {
private Container container;
private GridBagLayout layout;
private GridBagConstraints constraints;
private JTextField displayField;//计算结果显示区
private String lastCommand;//保存+,-,*,/,=命令
private double result;//保存计算结果
private boolean start;//判断是否为数字的开始
public Calculator() {
super("Calculator");
container=getContentPane();
layout=new GridBagLayout();
container.setLayout(layout);
constraints=new GridBagConstraints();
start=true;
result=0;
lastCommand = "=";
displayField=new JTextField(20);
displayField.setHorizontalAlignment(JTextField.RIGHT);
constraints.gridx=0;
constraints.gridy=0;
constraints.gridwidth=4;
constraints.gridheight=1;
constraints.fill=GridBagConstraints.BOTH;
constraints.weightx=100;
constraints.weighty=100;
layout.setConstraints(displayField,constraints);
container.add(displayField);
ActionListener insert = new InsertAction();
ActionListener command = new CommandAction();
addButton("Backspace",0,1,2,1,insert);
addButton("CE",2,1,1,1,insert);
addButton("C",3,1,1,1,insert);
addButton("7",0,2,1,1,insert);
addButton("8",1,2,1,1,insert);
addButton("9",2,2,1,1,insert);
addButton("/",3,2,1,1,command);
addButton("4",0,3,1,1,insert);
addButton("5",1,3,1,1,insert);
addButton("6",2,3,1,1,insert);
addButton("*",3,3,1,1,command);
addButton("1",0,4,1,1,insert);
addButton("2",1,4,1,1,insert);
addButton("3",2,4,1,1,insert);
addButton("-",3,4,1,1,command);
addButton("0",0,5,1,1,insert);
addButton("+/-",1,5,1,1,insert);//只显示"-"号,"+"没有实用价值
addButton(".",2,5,1,1,insert);
addButton("+",3,5,1,1,command);
addButton("=",0,6,4,1,command);
setSize(300,300);
setVisible(true);
}
private void addButton(String label,int row,int column,int with,int height,ActionListener listener) {
JButton button=new JButton(label);
constraints.gridx=row;
constraints.gridy=column;
constraints.gridwidth=with;
constraints.gridheight=height;
constraints.fill=GridBagConstraints.BOTH;
button.addActionListener(listener);
layout.setConstraints(button,constraints);
container.add(button);
}
private class InsertAction implements ActionListener {
public void actionPerformed(ActionEvent event) {
String input=event.getActionCommand();
if (start) {
displayField.setText("");
start=false;
if(input.equals("+/-"))
displayField.setText(displayField.getText()+"-");
}
if(!input.equals("+/-")) {
if(input.equals("Backspace")) {
String str=displayField.getText();
if(str.length()>0)
displayField.setText(str.substring(0,str.length()-1));
}else if(input.equals("CE")||input.equals("C")) {
displayField.setText("0");
start=true;
}else
displayField.setText(displayField.getText()+input);
}
}
}
private class CommandAction implements ActionListener {
public void actionPerformed(ActionEvent evt) {
String command=evt.getActionCommand();
if(start) {
lastCommand=command;
}else {
calculate(Double.parseDouble(displayField.getText()));
lastCommand=command;
start=true;
}
}
}
public void calculate(double x) {
if (lastCommand.equals("+")) result+= x;
else if (lastCommand.equals("-")) result-=x;
else if (lastCommand.equals("*")) result*=x;
else if (lastCommand.equals("/")) result/=x;
else if (lastCommand.equals("=")) result=x;
displayField.setText(""+ result);
}
public static void main(String []args) {
Calculator calculator=new Calculator();
calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
『贰』 恐龙有钱算力和dec有什么用
平台如果开设交易后,dec将成为股份形式,也可以有机会在虚拟平台交易,现在的100dec也许未来能值100万rbm说不一定,就看平台未来运营的怎样了
『叁』 用JavaScript做个网页版的计算器
哎呀!这个简单!!我给你啦!!!下面就是用Jscript写的计算器了复制后保存一切就OK的啦!!!!!!!!!
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--written by GoldHuman li hai-->
<!--2000.8-->
<title>科学计算器</title>
<style>
<!--
BODY {
font-family: "宋体", "Arial", "Times New Roman";
font-size: 9pt;
background-color: #edf0e1;
color: #0001fC;
background-attachment: fixed;
}
td{font-family: "宋体", "Arial Narrow", "Times New Roman"; font-size:9pt; font-color:#000000}
//-->
</style>
<script language="javascript">
<!--
var endNumber=true
var mem=0
var carry=10
var hexnum="0123456789abcdef"
var angle="d"
var stack=""
var level="0"
var layer=0
//数字键
function inputkey(key)
{
var index=key.charCodeAt(0);
if ((carry==2 && (index==48 || index==49))
|| (carry==8 && index>=48 && index<=55)
|| (carry==10 && (index>=48 && index<=57 || index==46))
|| (carry==16 && ((index>=48 && index<=57) || (index>=97 && index<=102))))
if(endNumber)
{
endNumber=false
document.calc.display.value = key
}
else if(document.calc.display.value == null || document.calc.display.value == "0")
document.calc.display.value = key
else
document.calc.display.value += key
}
function changeSign()
{
if (document.calc.display.value!="0")
if(document.calc.display.value.substr(0,1) == "-")
document.calc.display.value = document.calc.display.value.substr(1)
else
document.calc.display.value = "-" + document.calc.display.value
}
//函数键
function inputfunction(fun,shiftfun)
{
endNumber=true
if (document.calc.shiftf.checked)
document.calc.display.value=decto(funcalc(shiftfun,(todec(document.calc.display.value,carry))),carry)
else
document.calc.display.value=decto(funcalc(fun,(todec(document.calc.display.value,carry))),carry)
document.calc.shiftf.checked=false
document.calc.hypf.checked=false
inputshift()
}
function inputtrig(trig,arctrig,hyp,archyp)
{
if (document.calc.hypf.checked)
inputfunction(hyp,archyp)
else
inputfunction(trig,arctrig)
}
//运算符
function operation(join,newlevel)
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while (newlevel!=0 && (newlevel<=(level.charAt(level.length-1))))
{
temp=parse(temp)
level=level.slice(0,-1)
}
if (temp.match(/^(.*\d[\+\-\*\/\%\^\&\|x])?([+-]?[0-9a-f\.]+)$/))
document.calc.display.value=RegExp.$2
stack=stack.substr(0,stack.lastIndexOf("(")+1)+temp+join
document.calc.operator.value=" "+join+" "
level=level+newlevel
}
//括号
function addbracket()
{
endNumber=true
document.calc.display.value=0
stack=stack+"("
document.calc.operator.value=" "
level=level+0
layer+=1
document.calc.bracket.value="(="+layer
}
function disbracket()
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
stack=stack.substr(0,stack.lastIndexOf("("))
document.calc.operator.value=" "
level=level.slice(0,-1)
layer-=1
if (layer>0)
document.calc.bracket.value="(="+layer
else
document.calc.bracket.value=""
}
//等号
function result()
{
endNumber=true
while (layer>0)
disbracket()
var temp=stack+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
document.calc.bracket.value=""
document.calc.operator.value=""
stack=""
level="0"
}
//修改键
function backspace()
{
if (!endNumber)
{
if(document.calc.display.value.length>1)
document.calc.display.value=document.calc.display.value.substring(0,document.calc.display.value.length - 1)
else
document.calc.display.value=0
}
}
function clearall()
{
document.calc.display.value=0
endNumber=true
stack=""
level="0"
layer=""
document.calc.operator.value=""
document.calc.bracket.value=""
}
//转换键
function inputChangCarry(newcarry)
{
endNumber=true
document.calc.display.value=(decto(todec(document.calc.display.value,carry),newcarry))
carry=newcarry
document.calc.sin.disabled=(carry!=10)
document.calc.cos.disabled=(carry!=10)
document.calc.tan.disabled=(carry!=10)
document.calc.bt.disabled=(carry!=10)
document.calc.pi.disabled=(carry!=10)
document.calc.e.disabled=(carry!=10)
document.calc.kp.disabled=(carry!=10)
document.calc.k2.disabled=(carry<=2)
document.calc.k3.disabled=(carry<=2)
document.calc.k4.disabled=(carry<=2)
document.calc.k5.disabled=(carry<=2)
document.calc.k6.disabled=(carry<=2)
document.calc.k7.disabled=(carry<=2)
document.calc.k8.disabled=(carry<=8)
document.calc.k9.disabled=(carry<=8)
document.calc.ka.disabled=(carry<=10)
document.calc.kb.disabled=(carry<=10)
document.calc.kc.disabled=(carry<=10)
document.calc.kd.disabled=(carry<=10)
document.calc.ke.disabled=(carry<=10)
document.calc.kf.disabled=(carry<=10)
}
function inputChangAngle(angletype)
{
endNumber=true
angle=angletype
if (angle=="d")
document.calc.display.value=radiansToDegress(document.calc.display.value)
else
document.calc.display.value=degressToRadians(document.calc.display.value)
endNumber=true
}
function inputshift()
{
if (document.calc.shiftf.checked)
{
document.calc.bt.value="deg "
document.calc.ln.value="exp "
document.calc.log.value="expd"
if (document.calc.hypf.checked)
{
document.calc.sin.value="ahs "
document.calc.cos.value="ahc "
document.calc.tan.value="aht "
}
else
{
document.calc.sin.value="asin"
document.calc.cos.value="acos"
document.calc.tan.value="atan"
}
document.calc.sqr.value="x^.5"
document.calc.cube.value="x^.3"
document.calc.floor.value="小数"
}
else
{
document.calc.bt.value="d.ms"
document.calc.ln.value=" ln "
document.calc.log.value="log "
if (document.calc.hypf.checked)
{
document.calc.sin.value="hsin"
document.calc.cos.value="hcos"
document.calc.tan.value="htan"
}
else
{
document.calc.sin.value="sin "
document.calc.cos.value="cos "
document.calc.tan.value="tan "
}
document.calc.sqr.value="x^2 "
document.calc.cube.value="x^3 "
document.calc.floor.value="取整"
}
}
//存储器部分
function clearmemory()
{
mem=0
document.calc.memory.value=" "
}
function getmemory()
{
endNumber=true
document.calc.display.value=decto(mem,carry)
}
function putmemory()
{
endNumber=true
if (document.calc.display.value!=0)
{
mem=todec(document.calc.display.value,carry)
document.calc.memory.value=" M "
}
else
document.calc.memory.value=" "
}
function addmemory()
{
endNumber=true
mem=parseFloat(mem)+parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
function multimemory()
{
endNumber=true
mem=parseFloat(mem)*parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
//十进制转换
function todec(num,oldcarry)
{
if (oldcarry==10 || num==0) return(num)
var neg=(num.charAt(0)=="-")
if (neg) num=num.substr(1)
var newnum=0
for (var index=1;index<=num.length;index++)
newnum=newnum*oldcarry+hexnum.indexOf(num.charAt(index-1))
if (neg)
newnum=-newnum
return(newnum)
}
function decto(num,newcarry)
{
var neg=(num<0)
if (newcarry==10 || num==0) return(num)
num=""+Math.abs(num)
var newnum=""
while (num!=0)
{
newnum=hexnum.charAt(num%newcarry)+newnum
num=Math.floor(num/newcarry)
}
if (neg)
newnum="-"+newnum
return(newnum)
}
//表达式解析
function parse(string)
{
if (string.match(/^(.*\d[\+\-\*\/\%\^\&\|x\<])?([+-]?[0-9a-f\.]+)([\+\-\*\/\%\^\&\|x\<])([+-]?[0-9a-f\.]+)$/))
return(RegExp.$1+cypher(RegExp.$2,RegExp.$3,RegExp.$4))
else
return(string)
}
//数学运算和位运算
function cypher(left,join,right)
{
left=todec(left,carry)
right=todec(right,carry)
if (join=="+")
return(decto(parseFloat(left)+parseFloat(right),carry))
if (join=="-")
return(decto(left-right,carry))
if (join=="*")
return(decto(left*right,carry))
if (join=="/" && right!=0)
return(decto(left/right,carry))
if (join=="%")
return(decto(left%right,carry))
if (join=="&")
return(decto(left&right,carry))
if (join=="|")
return(decto(left|right,carry))
if (join=="^")
return(decto(Math.pow(left,right),carry))
if (join=="x")
return(decto(left^right,carry))
if (join=="<")
return(decto(left<<right,carry))
alert("除数不能为零")
return(left)
}
//函数计算
function funcalc(fun,num)
{
with(Math)
{
if (fun=="pi")
return(PI)
if (fun=="e")
return(E)
if (fun=="abs")
return(abs(num))
if (fun=="ceil")
return(ceil(num))
if (fun=="round")
return(round(num))
if (fun=="floor")
return(floor(num))
if (fun=="deci")
return(num-floor(num))
if (fun=="ln" && num>0)
return(log(num))
if (fun=="exp")
return(exp(num))
if (fun=="log" && num>0)
return(log(num)*LOG10E)
if (fun=="expdec")
return(pow(10,num))
if (fun=="cube")
return(num*num*num)
if (fun=="cubt")
return(pow(num,1/3))
if (fun=="sqr")
return(num*num)
if (fun=="sqrt" && num>=0)
return(sqrt(num))
if (fun=="!")
return(factorial(num))
if (fun=="recip" && num!=0)
return(1/num)
if (fun=="dms")
return(dms(num))
if (fun=="deg")
return(deg(num))
if (fun=="~")
return(~num)
if (angle=="d")
{
if (fun=="sin")
return(sin(degressToRadians(num)))
if (fun=="cos")
return(cos(degressToRadians(num)))
if (fun=="tan")
return(tan(degressToRadians(num)))
if (fun=="arcsin" && abs(num)<=1)
return(radiansToDegress(asin(num)))
if (fun=="arccos" && abs(num)<=1)
return(radiansToDegress(acos(num)))
if (fun=="arctan")
return(radiansToDegress(atan(num)))
}
else
{
if (fun=="sin")
return(sin(num))
if (fun=="cos")
return(cos(num))
if (fun=="tan")
return(tan(num))
if (fun=="arcsin" && abs(num)<=1)
return(asin(num))
if (fun=="arccos" && abs(num)<=1)
return(acos(num))
if (fun=="arctan")
return(atan(num))
}
if (fun=="hypsin")
return((exp(num)-exp(0-num))*0.5)
if (fun=="hypcos")
return((exp(num)+exp(-num))*0.5)
if (fun=="hyptan")
return((exp(num)-exp(-num))/(exp(num)+exp(-num)))
if (fun=="ahypsin" | fun=="hypcos" | fun=="hyptan")
{
alert("对不起,公式还没有查到!")
return(num)
}
alert("超出函数定义范围")
return(num)
}
}
function factorial(n)
{
n=Math.abs(parseInt(n))
var fac=1
for (;n>0;n-=1)
fac*=n
return(fac)
}
function dms(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor(60*(n-d))
var s=(n-d)*60-m
}
var dms=d+m/100+s*0.006
if (neg)
dms=-dms
return(dms)
}
function deg(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor((n-d)*100)
var s=(n-d)*100-m
}
var deg=d+m/60+s/36
if (neg)
deg=-deg
return(deg)
}
function degressToRadians(degress)
{
return(degress*Math.PI/180)
}
function radiansToDegress(radians)
{
return(radians*180/Math.PI)
}
//界面
//-->
</script>
</head>
<!--written by GoldHuman li hai-->
<!--2000.8-->
<body>
<div align="center">
<form name=calc>
<table border="1" width="500" height="250">
<tr>
<td height=50>
<table width=500>
<td>
<img src="../img/cp_logo.gif">
</td>
<td>
<div align=center>
<input type=text name="display" value="0" readonly size="40">
</div>
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width=500>
<tr>
<td width=290>
<input type=radio name="carry" onClick="inputChangCarry(16)">
十六进制
<input type=radio name="carry" checked onClick="inputChangCarry(10)">
十进制
<input type=radio name="carry" onClick="inputChangCarry(8)">
八进制
<input type=radio name="carry" onClick="inputChangCarry(2)">
二进制
</td>
<td>
</td>
<td width=135>
<input type=radio name="angle" value="d" onClick="inputChangAngle('d')" checked>
角度制
<input type=radio name="angle" value="r" onClick="inputChangAngle('r')">
弧度制
</td>
</tr>
</table>
<table width=500>
<tr>
<td width=170>
<input name="shiftf" type="checkbox" onclick="inputshift()">上档功能
<input name="hypf" type="checkbox" onclick="inputshift()">双曲函数
</td>
<td>
<input name="bracket" value="" type=text size=3 readonly style="background-color=lightgrey">
<input name="memory" value="" type=text size=3 readonly style="background-color=lightgrey">
<input name="operator" value="" type=text size=3 readonly style="background-color=lightgrey">
</td>
<td width=183>
<input type="button" value=" 退格 "
onclick="backspace()" style="color=red">
<input type="button" value=" 清屏 "
onClick="document.calc.display.value = 0 " style="color=red">
<input type="button" value=" 全清"
onClick="clearall()" style="color=red">
</td>
</tr>
</table>
<table width=500>
<tr>
<td>
<table>
<tr align=center>
<td>
<input name=pi type="button" value=" PI "
onClick="inputfunction('pi','pi')" style="color=blue">
</td>
<td>
<input name=e type="button" value=" E "
onClick="inputfunction('e','e')" style="color=blue">
</td>
<td>
<input name=bt type="button" value="d.ms"
onClick="inputfunction('dms','deg')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" ( "
onClick="addbracket()" style="color=#ff00ff">
</td>
<td>
<input type="button" value=" ) "
onClick="disbracket()" style="color=#ff00ff">
</td>
<td>
<input name=ln type="button" value=" ln "
onClick="inputfunction('ln','exp')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=sin type="button" value="sin "
onClick="inputtrig('sin','arcsin','hypsin','ahypsin')" style="color=#ff00ff">
</td>
<td>
<input type="button" value="x^y "
onClick="operation('^',7)" style="color=#ff00ff">
</td>
<td>
<input name=log type="button" value="log "
onClick="inputfunction('log','expdec')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=cos type="button" value="cos "
onClick="inputtrig('cos','arccos','hypcos','ahypcos')" style="color=#ff00ff">
</td>
<td>
<input name=cube type="button" value="x^3 "
onClick="inputfunction('cube','cubt')" style="color=#ff00ff">
</td>
<td>
<input type="button" value=" n! "
onClick="inputfunction('!','!')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=tan type="button" value="tan "
onClick="inputtrig('tan','arctan','hyptan','ahyptan')" style="color=#ff00ff">
</td>
<td>
<input name=sqr type="button" value="x^2 "
onClick="inputfunction('sqr','sqrt')" style="color=#ff00ff">
</td>
<td>
<input type="button" value="1/x "
onClick="inputfunction('recip','recip')" style="color=#ff00ff">
</td>
</tr>
</table>
</td>
<td width=30>
</td>
<td>
<table>
<tr>
<td>
<input type="button" value=" 储存 "
onClick="putmemory()" style="color=red">
</td>
</tr>
<td>
<input type="button" value=" 取存 "
onClick="getmemory()" style="color=red">
</td>
</tr>
<tr>
<td>
<input type="button" value=" 累存 "
onClick="addmemory()" style="color=red">
</td>
</tr>
<tr>
<td>
<input type="button" value=" 积存 "
onClick="multimemory()" style="color=red">
</td>
</tr>
<tr>
<td height="33">
<input type="button" value=" 清存 "
onClick="clearmemory()" style="color=red">
</td>
</tr>
</table>
</td>
<td width=30>
</td>
<td>
<table>
<tr align=center>
<td>
<input name=k7 type="button" value=" 7 "
onClick="inputkey('7')" style="color=blue">
</td>
<td>
<input name=k8 type="button" value=" 8 "
onClick="inputkey('8')" style="color=blue">
</td>
<td>
<input name=k9 type="button" value=" 9 "
onClick="inputkey('9')" style="color=blue">
</td>
<td>
<input type="button" value=" / "
onClick="operation('/',6)" style="color=red">
</td>
<td>
<input type="button" value="取余"
onClick="operation('%',6)" style="color=red">
</td>
<td>
<input type="button" value=" 与 "
onClick="operation('&',3)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input name=k4 type="button" value=" 4 "
onClick="inputkey('4')" style="color=blue">
</td>
<td>
<input name=k5 type="button" value=" 5 "
onClick="inputkey('5')" style="color=blue">
</td>
<td>
<input name=k6 type="button" value=" 6 "
onClick="inputkey('6')" style="color=blue">
</td>
<td>
<input type="button" value=" * "
onClick="operation('*',6)" style="color=red">
</td>
<td>
<input name=floor type="button" value="取整"
onClick="inputfunction('floor','deci')" style="color=red">
</td>
<td>
<input type="button" value=" 或 "
onClick="operation('|',1)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" 1 "
onClick="inputkey('1')" style="color=blue">
</td>
<td>
<input name=k2 type="button" value=" 2 "
onClick="inputkey('2')" style="color=blue">
</td>
<td>
<input name=k3 type="button" value=" 3 "
onClick="inputkey('3')" style="color=blue">
</td>
<td>
<input type="button" value=" - "
onClick="operation('-',5)" style="color=red">
</td>
<td>
<input type="button" value="左移"
onClick="operation('<',4)" style="color=red">
</td>
<td>
<input type="button" value=" 非 "
onClick="inputfunction('~','~')" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" 0 "
onClick="inputkey('0')" style="color=blue">
</td>
<td>
<input type="button" value="+/-"
onClick="changeSign()" style="color=blue">
</td>
<td>
<input name=kp type="button" value=" . "
onClick="inputkey('.')" style="color=blue">
</td>
<td>
<input type="button" value=" + "
onClick="operation('+',5)" style="color=red">
</td>
<td>
<input type="button" value=" = "
onClick="result()" style="color=red">
</td>
<td>
<input type="button" value="异或"
onClick="operation('x',2)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input name=ka type="button" value=" A "
onClick="inputkey('a')" style="color=blue" disabled=true>
</td>
<td>
<input name=kb type="button" value=" B "
onClick="inputkey('b')" style="color=blue" disabled=true>
</td>
<td>
<input name=kc type="button" value=" C "
onClick="inputkey('c')" style="color=blue" disabled=true>
</td>
<td>
<input name=kd type="button" value=" D "
onClick="inputkey('d')" style="color=blue" disabled=true>
</td>
<td>
<input name=ke type="button" value=" E"
onClick="inputkey('e')" style="color=blue" disabled=true>
</td>
<td>
<input name=kf type="button" value=" F"
onClick="inputkey('f')" style="color=blue" disabled=true>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
『肆』 制作java计算器
有分加没啊 !!!!!!
import java.awt.*;
import java.awt.event.*;
public class jisuanqi extends WindowAdapter {
Panel p1 = new Panel();
Panel p2 = new Panel();
Panel p3 = new Panel();
TextField txt;
private Button[] b = new Button[17];
private String ss[] = { "7", "8", "9", "+", "4", "5", "6", "-", "1", "2",
"3", "*", "清空", "0", "=", "/", "关闭" };
static double a;
static String s, str;// 定义变量 创建对像
public static void main(String args[]) {
(new jisuanqi()).frame();
}
public void frame() {
Frame fm = new Frame("简单计算器");
for (int i = 0; i <= 16; i++) {
b[i] = new Button(ss[i]);
}
for (int i = 0; i <= 15; i++) {
p2.add(b[i]);
} // 创建按钮 并添加到P2
b[16].setBackground(Color.yellow);
txt = new TextField(15);
txt.setEditable(false);
for (int i = 0; i <= 16; i++) {
b[i].addActionListener(new buttonlistener());// 添加监听器
}
b[16].addActionListener(new close());
fm.addWindowListener(this);
fm.setBackground(Color.red);
p1.setLayout(new BorderLayout());
p1.add(txt, "North");
p2.setLayout(new GridLayout(4, 4));
p3.setLayout(new BorderLayout());
p3.add(b[16]);
fm.add(p1, "North");
fm.add(p2, "Center");
fm.add(p3, "South");
fm.pack();
fm.setVisible(true);// 都是些窗中设置 添加相关组件和监听器
}
public void windowClosing(WindowEvent e) {
System.exit(0);// 退出系统
}
class buttonlistener implements ActionListener {// 编写监听器事件 通过按键得出给果
public void actionPerformed(ActionEvent e) {
Button btn = (Button) e.getSource();
if (btn.getLabel() == "=") {
jisuan();
str = String.valueOf(a);
txt.setText(str);
s = "";
} else if (btn.getLabel() == "+") {
jisuan();
txt.setText("");
s = "+";
} else if (btn.getLabel() == "-") {
jisuan();
txt.setText("");
s = "-";
} else if (btn.getLabel() == "/") {
jisuan();
txt.setText("");
s = "/";
} else if (btn.getLabel() == "*") {
jisuan();
txt.setText("");
s = "*";
} else {
txt.setText(txt.getText() + btn.getLabel());
if (btn.getLabel() == "清空")
txt.setText("");
}
}
public void jisuan() {// 编写具体计算方法
if (s == "+")
a += Double.parseDouble(txt.getText());
else if (s == "-")
a -= Double.parseDouble(txt.getText());
else if (s == "*")
a *= Double.parseDouble(txt.getText());
else if (s == "/")
a /= Double.parseDouble(txt.getText());
else
a = Double.parseDouble(txt.getText());
}
}
}
class close implements ActionListener {// 退出
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
『伍』 DCR, Decred是什么
德信币(Decred)是一种类似于比特币的加密货币,其主要应用包括社区投入、开放管理和可持续的资金筹集与开发。贡献者:比特网bitewang
『陆』 java计算器代码,请帮我修改
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>科学计算器</title>
<style>
<!--
BODY {font-size: 12px;background-color: #d4d4d4;color: #0001fC;background-attachment: fixed;}
td{font-size:12px; font-color:#000000}
//-->
</style>
<script language="javascript">
<!--
var endNumber=true
var mem=0
var carry=10
var hexnum="0123456789abcdef"
var angle="d"
var stack=""
var level="0"
var layer=0
//数字键
function inputkey(key)
{
var index=key.charCodeAt(0);
if ((carry==2 && (index==48 || index==49))
|| (carry==8 && index>=48 && index<=55)
|| (carry==10 && (index>=48 && index<=57 || index==46))
|| (carry==16 && ((index>=48 && index<=57) || (index>=97 && index<=102))))
if(endNumber)
{
endNumber=false
document.calc.display.value = key
}
else if(document.calc.display.value == null || document.calc.display.value == "0")
document.calc.display.value = key
else
document.calc.display.value += key
}
function changeSign()
{
if (document.calc.display.value!="0")
if(document.calc.display.value.substr(0,1) == "-")
document.calc.display.value = document.calc.display.value.substr(1)
else
document.calc.display.value = "-" + document.calc.display.value
}
//函数键
function inputfunction(fun,shiftfun)
{
endNumber=true
if (document.calc.shiftf.checked)
document.calc.display.value=decto(funcalc(shiftfun,(todec(document.calc.display.value,carry))),carry)
else
document.calc.display.value=decto(funcalc(fun,(todec(document.calc.display.value,carry))),carry)
document.calc.shiftf.checked=false
document.calc.hypf.checked=false
inputshift()
}
function inputtrig(trig,arctrig,hyp,archyp)
{
if (document.calc.hypf.checked)
inputfunction(hyp,archyp)
else
inputfunction(trig,arctrig)
}
//运算符
function operation(join,newlevel)
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while (newlevel!=0 && (newlevel<=(level.charAt(level.length-1))))
{
temp=parse(temp)
level=level.slice(0,-1)
}
if (temp.match(/^(.*\d[\+\-\*\/\%\^\&\|x])?([+-]?[0-9a-f\.]+)$/))
document.calc.display.value=RegExp.$2
stack=stack.substr(0,stack.lastIndexOf("(")+1)+temp+join
document.calc.operator.value=" "+join+" "
level=level+newlevel
}
//括号
function addbracket()
{
endNumber=true
document.calc.display.value=0
stack=stack+"("
document.calc.operator.value=" "
level=level+0
layer+=1
document.calc.bracket.value="(="+layer
}
function disbracket()
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
stack=stack.substr(0,stack.lastIndexOf("("))
document.calc.operator.value=" "
level=level.slice(0,-1)
layer-=1
if (layer>0)
document.calc.bracket.value="(="+layer
else
document.calc.bracket.value=""
}
//等号
function result()
{
endNumber=true
while (layer>0)
disbracket()
var temp=stack+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
document.calc.bracket.value=""
document.calc.operator.value=""
stack=""
level="0"
}
//修改键
function backspace()
{
if (!endNumber)
{
if(document.calc.display.value.length>1)
document.calc.display.value=document.calc.display.value.substring(0,document.calc.display.value.length - 1)
else
document.calc.display.value=0
}
}
function clearall()
{
document.calc.display.value=0
endNumber=true
stack=""
level="0"
layer=""
document.calc.operator.value=""
document.calc.bracket.value=""
}
//转换键
function inputChangCarry(newcarry)
{
endNumber=true
document.calc.display.value=(decto(todec(document.calc.display.value,carry),newcarry))
carry=newcarry
document.calc.sin.disabled=(carry!=10)
document.calc.cos.disabled=(carry!=10)
document.calc.tan.disabled=(carry!=10)
document.calc.bt.disabled=(carry!=10)
document.calc.pi.disabled=(carry!=10)
document.calc.e.disabled=(carry!=10)
document.calc.kp.disabled=(carry!=10)
document.calc.k2.disabled=(carry<=2)
document.calc.k3.disabled=(carry<=2)
document.calc.k4.disabled=(carry<=2)
document.calc.k5.disabled=(carry<=2)
document.calc.k6.disabled=(carry<=2)
document.calc.k7.disabled=(carry<=2)
document.calc.k8.disabled=(carry<=8)
document.calc.k9.disabled=(carry<=8)
document.calc.ka.disabled=(carry<=10)
document.calc.kb.disabled=(carry<=10)
document.calc.kc.disabled=(carry<=10)
document.calc.kd.disabled=(carry<=10)
document.calc.ke.disabled=(carry<=10)
document.calc.kf.disabled=(carry<=10)
}
function inputChangAngle(angletype)
{
endNumber=true
angle=angletype
if (angle=="d")
document.calc.display.value=radiansToDegress(document.calc.display.value)
else
document.calc.display.value=degressToRadians(document.calc.display.value)
endNumber=true
}
function inputshift()
{
if (document.calc.shiftf.checked)
{
document.calc.bt.value="deg "
document.calc.ln.value="exp "
document.calc.log.value="expd"
if (document.calc.hypf.checked)
{
document.calc.sin.value="ahs "
document.calc.cos.value="ahc "
document.calc.tan.value="aht "
}
else
{
document.calc.sin.value="asin"
document.calc.cos.value="acos"
document.calc.tan.value="atan"
}
document.calc.sqr.value="x^.5"
document.calc.cube.value="x^.3"
document.calc.floor.value="小数"
}
else
{
document.calc.bt.value="d.ms"
document.calc.ln.value=" ln "
document.calc.log.value="log "
if (document.calc.hypf.checked)
{
document.calc.sin.value="hsin"
document.calc.cos.value="hcos"
document.calc.tan.value="htan"
}
else
{
document.calc.sin.value="sin "
document.calc.cos.value="cos "
document.calc.tan.value="tan "
}
document.calc.sqr.value="x^2 "
document.calc.cube.value="x^3 "
document.calc.floor.value="取整"
}
}
//存储器部分
function clearmemory()
{
mem=0
document.calc.memory.value=" "
}
function getmemory()
{
endNumber=true
document.calc.display.value=decto(mem,carry)
}
function putmemory()
{
endNumber=true
if (document.calc.display.value!=0)
{
mem=todec(document.calc.display.value,carry)
document.calc.memory.value=" M "
}
else
document.calc.memory.value=" "
}
function addmemory()
{
endNumber=true
mem=parseFloat(mem)+parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
function multimemory()
{
endNumber=true
mem=parseFloat(mem)*parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
//十进制转换
function todec(num,oldcarry)
{
if (oldcarry==10 || num==0) return(num)
var neg=(num.charAt(0)=="-")
if (neg) num=num.substr(1)
var newnum=0
for (var index=1;index<=num.length;index++)
newnum=newnum*oldcarry+hexnum.indexOf(num.charAt(index-1))
if (neg)
newnum=-newnum
return(newnum)
}
function decto(num,newcarry)
{
var neg=(num<0)
if (newcarry==10 || num==0) return(num)
num=""+Math.abs(num)
var newnum=""
while (num!=0)
{
newnum=hexnum.charAt(num%newcarry)+newnum
num=Math.floor(num/newcarry)
}
if (neg)
newnum="-"+newnum
return(newnum)
}
//表达式解析
function parse(string)
{
if (string.match(/^(.*\d[\+\-\*\/\%\^\&\|x\<])?([+-]?[0-9a-f\.]+)([\+\-\*\/\%\^\&\|x\<])([+-]?[0-9a-f\.]+)$/))
return(RegExp.$1+cypher(RegExp.$2,RegExp.$3,RegExp.$4))
else
return(string)
}
//数学运算和位运算
function cypher(left,join,right)
{
left=todec(left,carry)
right=todec(right,carry)
if (join=="+")
return(decto(parseFloat(left)+parseFloat(right),carry))
if (join=="-")
return(decto(left-right,carry))
if (join=="*")
return(decto(left*right,carry))
if (join=="/" && right!=0)
return(decto(left/right,carry))
if (join=="%")
return(decto(left%right,carry))
if (join=="&")
return(decto(left&right,carry))
if (join=="|")
return(decto(left|right,carry))
if (join=="^")
return(decto(Math.pow(left,right),carry))
if (join=="x")
return(decto(left^right,carry))
if (join=="<")
return(decto(left<<right,carry))
alert("除数不能为零")
return(left)
}
//函数计算
function funcalc(fun,num)
{
with(Math)
{
if (fun=="pi")
return(PI)
if (fun=="e")
return(E)
if (fun=="abs")
return(abs(num))
if (fun=="ceil")
return(ceil(num))
if (fun=="round")
return(round(num))
if (fun=="floor")
return(floor(num))
if (fun=="deci")
return(num-floor(num))
if (fun=="ln" && num>0)
return(log(num))
if (fun=="exp")
return(exp(num))
if (fun=="log" && num>0)
return(log(num)*LOG10E)
if (fun=="expdec")
return(pow(10,num))
if (fun=="cube")
return(num*num*num)
if (fun=="cubt")
return(pow(num,1/3))
if (fun=="sqr")
return(num*num)
if (fun=="sqrt" && num>=0)
return(sqrt(num))
if (fun=="!")
return(factorial(num))
if (fun=="recip" && num!=0)
return(1/num)
if (fun=="dms")
return(dms(num))
if (fun=="deg")
return(deg(num))
if (fun=="~")
return(~num)
if (angle=="d")
{
if (fun=="sin")
return(sin(degressToRadians(num)))
if (fun=="cos")
return(cos(degressToRadians(num)))
if (fun=="tan")
return(tan(degressToRadians(num)))
if (fun=="arcsin" && abs(num)<=1)
return(radiansToDegress(asin(num)))
if (fun=="arccos" && abs(num)<=1)
return(radiansToDegress(acos(num)))
if (fun=="arctan")
return(radiansToDegress(atan(num)))
}
else
{
if (fun=="sin")
return(sin(num))
if (fun=="cos")
return(cos(num))
if (fun=="tan")
return(tan(num))
if (fun=="arcsin" && abs(num)<=1)
return(asin(num))
if (fun=="arccos" && abs(num)<=1)
return(acos(num))
if (fun=="arctan")
return(atan(num))
}
if (fun=="hypsin")
return((exp(num)-exp(0-num))*0.5)
if (fun=="hypcos")
return((exp(num)+exp(-num))*0.5)
if (fun=="hyptan")
return((exp(num)-exp(-num))/(exp(num)+exp(-num)))
if (fun=="ahypsin" | fun=="hypcos" | fun=="hyptan")
{
alert("对不起,公式还没有查到!")
return(num)
}
alert("超出函数定义范围")
return(num)
}
}
function factorial(n)
{
n=Math.abs(parseInt(n))
var fac=1
for (;n>0;n-=1)
fac*=n
return(fac)
}
function dms(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor(60*(n-d))
var s=(n-d)*60-m
}
var dms=d+m/100+s*0.006
if (neg)
dms=-dms
return(dms)
}
function deg(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor((n-d)*100)
var s=(n-d)*100-m
}
var deg=d+m/60+s/36
if (neg)
deg=-deg
return(deg)
}
function degressToRadians(degress)
{
return(degress*Math.PI/180)
}
function radiansToDegress(radians)
{
return(radians*180/Math.PI)
}
//界面
//-->
</script>
</head>
<!--written by GoldHuman li hai-->
<!--2000.8-->
<body>
<div align="center">
<form name=calc>
<table border="1" width="500" height="250">
<tr>
<td height=50>
<table width=500>
<td width="133">
</td>
<td width="353">
<div align=center>
<input type=text name="display" value="0" readonly size="40">
</div>
</td>
</table>
</td>
</tr>
<tr>
<td>
<table width=500>
<tr>
<td width=290>
<input type=radio name="carry" onClick="inputChangCarry(16)">
十六进制
<input type=radio name="carry" checked onClick="inputChangCarry(10)">
十进制
<input type=radio name="carry" onClick="inputChangCarry(8)">
八进制
<input type=radio name="carry" onClick="inputChangCarry(2)">
二进制
</td>
<td>
</td>
<td width=135>
<input type=radio name="angle" value="d" onClick="inputChangAngle('d')" checked>
角度制
<input type=radio name="angle" value="r" onClick="inputChangAngle('r')">
弧度制
</td>
</tr>
</table>
<table width=500>
<tr>
<td width=170>
<input name="shiftf" type="checkbox" onclick="inputshift()">上档功能
<input name="hypf" type="checkbox" onclick="inputshift()">双曲函数
</td>
<td>
<input name="bracket" value="" type=text size=3 readonly style="background-color=lightgrey">
<input name="memory" value="" type=text size=3 readonly style="background-color=lightgrey">
<input name="operator" value="" type=text size=3 readonly style="background-color=lightgrey">
</td>
<td width=183>
<input type="button" value=" 退格 "
onclick="backspace()" style="color=red">
<input type="button" value=" 清屏 "
onClick="document.calc.display.value = 0 " style="color=red">
<input type="button" value=" 全清"
onClick="clearall()" style="color=red">
</td>
</tr>
</table>
<table width=500>
<tr>
<td>
<table>
<tr align=center>
<td>
<input name=pi type="button" value=" PI "
onClick="inputfunction('pi','pi')" style="color=blue">
</td>
<td>
<input name=e type="button" value=" E "
onClick="inputfunction('e','e')" style="color=blue">
</td>
<td>
<input name=bt type="button" value="d.ms"
onClick="inputfunction('dms','deg')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" ( "
onClick="addbracket()" style="color=#ff00ff">
</td>
<td>
<input type="button" value=" ) "
onClick="disbracket()" style="color=#ff00ff">
</td>
<td>
<input name=ln type="button" value=" ln "
onClick="inputfunction('ln','exp')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=sin type="button" value="sin "
onClick="inputtrig('sin','arcsin','hypsin','ahypsin')" style="color=#ff00ff">
</td>
<td>
<input type="button" value="x^y "
onClick="operation('^',7)" style="color=#ff00ff">
</td>
<td>
<input name=log type="button" value="log "
onClick="inputfunction('log','expdec')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=cos type="button" value="cos "
onClick="inputtrig('cos','arccos','hypcos','ahypcos')" style="color=#ff00ff">
</td>
<td>
<input name=cube type="button" value="x^3 "
onClick="inputfunction('cube','cubt')" style="color=#ff00ff">
</td>
<td>
<input type="button" value=" n! "
onClick="inputfunction('!','!')" style="color=#ff00ff">
</td>
</tr>
<tr align=center>
<td>
<input name=tan type="button" value="tan "
onClick="inputtrig('tan','arctan','hyptan','ahyptan')" style="color=#ff00ff">
</td>
<td>
<input name=sqr type="button" value="x^2 "
onClick="inputfunction('sqr','sqrt')" style="color=#ff00ff">
</td>
<td>
<input type="button" value="1/x "
onClick="inputfunction('recip','recip')" style="color=#ff00ff">
</td>
</tr>
</table>
</td>
<td width=30>
</td>
<td>
<table>
<tr>
<td>
<input type="button" value=" 储存 "
onClick="putmemory()" style="color=red">
</td>
</tr>
<td>
<input type="button" value=" 取存 "
onClick="getmemory()" style="color=red">
</td>
</tr>
<tr>
<td>
<input type="button" value=" 累存 "
onClick="addmemory()" style="color=red">
</td>
</tr>
<tr>
<td>
<input type="button" value=" 积存 "
onClick="multimemory()" style="color=red">
</td>
</tr>
<tr>
<td height="33">
<input type="button" value=" 清存 "
onClick="clearmemory()" style="color=red">
</td>
</tr>
</table>
</td>
<td width=30>
</td>
<td>
<table>
<tr align=center>
<td>
<input name=k7 type="button" value=" 7 "
onClick="inputkey('7')" style="color=blue">
</td>
<td>
<input name=k8 type="button" value=" 8 "
onClick="inputkey('8')" style="color=blue">
</td>
<td>
<input name=k9 type="button" value=" 9 "
onClick="inputkey('9')" style="color=blue">
</td>
<td>
<input type="button" value=" / "
onClick="operation('/',6)" style="color=red">
</td>
<td>
<input type="button" value="取余"
onClick="operation('%',6)" style="color=red">
</td>
<td>
<input type="button" value=" 与 "
onClick="operation('&',3)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input name=k4 type="button" value=" 4 "
onClick="inputkey('4')" style="color=blue">
</td>
<td>
<input name=k5 type="button" value=" 5 "
onClick="inputkey('5')" style="color=blue">
</td>
<td>
<input name=k6 type="button" value=" 6 "
onClick="inputkey('6')" style="color=blue">
</td>
<td>
<input type="button" value=" * "
onClick="operation('*',6)" style="color=red">
</td>
<td>
<input name=floor type="button" value="取整"
onClick="inputfunction('floor','deci')" style="color=red">
</td>
<td>
<input type="button" value=" 或 "
onClick="operation('|',1)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" 1 "
onClick="inputkey('1')" style="color=blue">
</td>
<td>
<input name=k2 type="button" value=" 2 "
onClick="inputkey('2')" style="color=blue">
</td>
<td>
<input name=k3 type="button" value=" 3 "
onClick="inputkey('3')" style="color=blue">
</td>
<td>
<input type="button" value=" - "
onClick="operation('-',5)" style="color=red">
</td>
<td>
<input type="button" value="左移"
onClick="operation('<',4)" style="color=red">
</td>
<td>
<input type="button" value=" 非 "
onClick="inputfunction('~','~')" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input type="button" value=" 0 "
onClick="inputkey('0')" style="color=blue">
</td>
<td>
<input type="button" value="+/-"
onClick="changeSign()" style="color=blue">
</td>
<td>
<input name=kp type="button" value=" . "
onClick="inputkey('.')" style="color=blue">
</td>
<td>
<input type="button" value=" + "
onClick="operation('+',5)" style="color=red">
</td>
<td>
<input type="button" value=" = "
onClick="result()" style="color=red">
</td>
<td>
<input type="button" value="异或"
onClick="operation('x',2)" style="color=red">
</td>
</tr>
<tr align=center>
<td>
<input name=ka type="button" value=" A "
onClick="inputkey('a')" style="color=blue" disabled=true>
</td>
<td>
<input name=kb type="button" value=" B "
onClick="inputkey('b')" style="color=blue" disabled=true>
</td>
<td>
<input name=kc type="button" value=" C "
onClick="inputkey('c')" style="color=blue" disabled=true>
</td>
<td>
<input name=kd type="button" value=" D "
onClick="inputkey('d')" style="color=blue" disabled=true>
</td>
<td>
<input name=ke type="button" value=" E"
onClick="inputkey('e')" style="color=blue" disabled=true>
</td>
<td>
<input name=kf type="button" value=" F"
onClick="inputkey('f')" style="color=blue" disabled=true>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
『柒』 什么是POW和POS,二者区别联系
POW:全称Proof of Work,工作量证明。
POS:全称Proof of Stake,权益证明。
区别是:
1、POW机制:工作量证明机制即对于工作量的证明,是生成要加入到区块链中的一笔新的交易信息(即新区块)时必须满足的要求。在基于工作量证明机制构建的区块链网络中,节点通过计算随机哈希散列的数值解争夺记账权,求得正确的数值解以生成区块的能力是节点算力的具体表现。
2、POS机制:权益证明要求证明人提供一定数量加密货币的所有权即可。权益证明机制的运作方式是,当创造一个新区块时,矿工需要创建一个“币权”交易,交易会按照预先设定的比例把一些币发送给矿工本身。权益证明机制根据每个节点拥有代币的比例和时间,依据算法等比例地降低节点的挖矿难度,从而加快了寻找随机数的速度。
(7)decred算力计算器扩展阅读:
比特币(BitCoin)的概念最初由中本聪在2009年提出,根据中本聪的思路设计发布的开源软件以及建构其上的P2P网络。比特币是一种P2P形式的数字货币。点对点的传输意味着一个去中心化的支付系统。
与大多数货币不同,比特币不依靠特定货币机构发行,它依据特定算法,通过大量的计算产生,比特币经济使用整个P2P网络中众多节点构成的分布式数据库来确认并记录所有的交易行为,并使用密码学的设计来确保货币流通各个环节安全性。P2P的去中心化特性与算法本身可以确保无法通过大量制造比特币来人为操控币值。
『捌』 D9矿机收益怎么样
目前收益一天几十,
『玖』 请问谁能用java语言,为我写一个计算器的小程序
<!--开始 -->
<STYLE>BODY {
BACKGROUND-ATTACHMENT: fixed; BACKGROUND-COLOR: #edf0e1; COLOR: #0001fc; FONT-FAMILY: "宋体", "Arial", "Times New Roman"; FONT-SIZE: 9pt
}
TD {
FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt; font-color: #000000
}
</STYLE>
<SCRIPT language=javascript>
<!--
var endNumber=true
var mem=0
var carry=10
var hexnum="0123456789abcdef"
var angle="d"
var stack=""
var level="0"
var layer=0
//数字键
function inputkey(key)
{
var index=key.charCodeAt(0);
if ((carry==2 && (index==48 || index==49))
|| (carry==8 && index>=48 && index<=55)
|| (carry==10 && (index>=48 && index<=57 || index==46))
|| (carry==16 && ((index>=48 && index<=57) || (index>=97 && index<=102))))
if(endNumber)
{
endNumber=false
document.calc.display.value = key
}
else if(document.calc.display.value == null || document.calc.display.value == "0")
document.calc.display.value = key
else
document.calc.display.value += key
}
function changeSign()
{
if (document.calc.display.value!="0")
if(document.calc.display.value.substr(0,1) == "-")
document.calc.display.value = document.calc.display.value.substr(1)
else
document.calc.display.value = "-" + document.calc.display.value
}
//函数键
function inputfunction(fun,shiftfun)
{
endNumber=true
if (document.calc.shiftf.checked)
document.calc.display.value=decto(funcalc(shiftfun,(todec(document.calc.display.value,carry))),carry)
else
document.calc.display.value=decto(funcalc(fun,(todec(document.calc.display.value,carry))),carry)
document.calc.shiftf.checked=false
document.calc.hypf.checked=false
inputshift()
}
function inputtrig(trig,arctrig,hyp,archyp)
{
if (document.calc.hypf.checked)
inputfunction(hyp,archyp)
else
inputfunction(trig,arctrig)
}
//运算符
function operation(join,newlevel)
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while (newlevel!=0 && (newlevel<=(level.charAt(level.length-1))))
{
temp=parse(temp)
level=level.slice(0,-1)
}
if (temp.match(/^(.*\d[\+\-\*\/\%\^\&\|x])?([+-]?[0-9a-f\.]+)$/))
document.calc.display.value=RegExp.$2
stack=stack.substr(0,stack.lastIndexOf("(")+1)+temp+join
document.calc.operator.value=" "+join+" "
level=level+newlevel
}
//括号
function addbracket()
{
endNumber=true
document.calc.display.value=0
stack=stack+"("
document.calc.operator.value=" "
level=level+0
layer+=1
document.calc.bracket.value="(="+layer
}
function disbracket()
{
endNumber=true
var temp=stack.substr(stack.lastIndexOf("(")+1)+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
stack=stack.substr(0,stack.lastIndexOf("("))
document.calc.operator.value=" "
level=level.slice(0,-1)
layer-=1
if (layer>0)
document.calc.bracket.value="(="+layer
else
document.calc.bracket.value=""
}
//等号
function result()
{
endNumber=true
while (layer>0)
disbracket()
var temp=stack+document.calc.display.value
while ((level.charAt(level.length-1))>0)
{
temp=parse(temp)
level=level.slice(0,-1)
}
document.calc.display.value=temp
document.calc.bracket.value=""
document.calc.operator.value=""
stack=""
level="0"
}
//修改键
function backspace()
{
if (!endNumber)
{
if(document.calc.display.value.length>1)
document.calc.display.value=document.calc.display.value.substring(0,document.calc.display.value.length - 1)
else
document.calc.display.value=0
}
}
function clearall()
{
document.calc.display.value=0
endNumber=true
stack=""
level="0"
layer=""
document.calc.operator.value=""
document.calc.bracket.value=""
}
//转换键
function inputChangCarry(newcarry)
{
endNumber=true
document.calc.display.value=(decto(todec(document.calc.display.value,carry),newcarry))
carry=newcarry
document.calc.sin.disabled=(carry!=10)
document.calc.cos.disabled=(carry!=10)
document.calc.tan.disabled=(carry!=10)
document.calc.bt.disabled=(carry!=10)
document.calc.pi.disabled=(carry!=10)
document.calc.e.disabled=(carry!=10)
document.calc.kp.disabled=(carry!=10)
document.calc.k2.disabled=(carry<=2)
document.calc.k3.disabled=(carry<=2)
document.calc.k4.disabled=(carry<=2)
document.calc.k5.disabled=(carry<=2)
document.calc.k6.disabled=(carry<=2)
document.calc.k7.disabled=(carry<=2)
document.calc.k8.disabled=(carry<=8)
document.calc.k9.disabled=(carry<=8)
document.calc.ka.disabled=(carry<=10)
document.calc.kb.disabled=(carry<=10)
document.calc.kc.disabled=(carry<=10)
document.calc.kd.disabled=(carry<=10)
document.calc.ke.disabled=(carry<=10)
document.calc.kf.disabled=(carry<=10)
}
function inputChangAngle(angletype)
{
endNumber=true
angle=angletype
if (angle=="d")
document.calc.display.value=radiansToDegress(document.calc.display.value)
else
document.calc.display.value=degressToRadians(document.calc.display.value)
endNumber=true
}
function inputshift()
{
if (document.calc.shiftf.checked)
{
document.calc.bt.value="deg "
document.calc.ln.value="exp "
document.calc.log.value="expd"
if (document.calc.hypf.checked)
{
document.calc.sin.value="ahs "
document.calc.cos.value="ahc "
document.calc.tan.value="aht "
}
else
{
document.calc.sin.value="asin"
document.calc.cos.value="acos"
document.calc.tan.value="atan"
}
document.calc.sqr.value="x^.5"
document.calc.cube.value="x^.3"
document.calc.floor.value="小数"
}
else
{
document.calc.bt.value="d.ms"
document.calc.ln.value=" ln "
document.calc.log.value="log "
if (document.calc.hypf.checked)
{
document.calc.sin.value="hsin"
document.calc.cos.value="hcos"
document.calc.tan.value="htan"
}
else
{
document.calc.sin.value="sin "
document.calc.cos.value="cos "
document.calc.tan.value="tan "
}
document.calc.sqr.value="x^2 "
document.calc.cube.value="x^3 "
document.calc.floor.value="取整"
}
}
//存储器部分
function clearmemory()
{
mem=0
document.calc.memory.value=" "
}
function getmemory()
{
endNumber=true
document.calc.display.value=decto(mem,carry)
}
function putmemory()
{
endNumber=true
if (document.calc.display.value!=0)
{
mem=todec(document.calc.display.value,carry)
document.calc.memory.value=" M "
}
else
document.calc.memory.value=" "
}
function addmemory()
{
endNumber=true
mem=parseFloat(mem)+parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
function multimemory()
{
endNumber=true
mem=parseFloat(mem)*parseFloat(todec(document.calc.display.value,carry))
if (mem==0)
document.calc.memory.value=" "
else
document.calc.memory.value=" M "
}
//十进制转换
function todec(num,oldcarry)
{
if (oldcarry==10 || num==0) return(num)
var neg=(num.charAt(0)=="-")
if (neg) num=num.substr(1)
var newnum=0
for (var index=1;index<=num.length;index++)
newnum=newnum*oldcarry+hexnum.indexOf(num.charAt(index-1))
if (neg)
newnum=-newnum
return(newnum)
}
function decto(num,newcarry)
{
var neg=(num<0)
if (newcarry==10 || num==0) return(num)
num=""+Math.abs(num)
var newnum=""
while (num!=0)
{
newnum=hexnum.charAt(num%newcarry)+newnum
num=Math.floor(num/newcarry)
}
if (neg)
newnum="-"+newnum
return(newnum)
}
//表达式解析
function parse(string)
{
if (string.match(/^(.*\d[\+\-\*\/\%\^\&\|x\<])?([+-]?[0-9a-f\.]+)([\+\-\*\/\%\^\&\|x\<])([+-]?[0-9a-f\.]+)$/))
return(RegExp.$1+cypher(RegExp.$2,RegExp.$3,RegExp.$4))
else
return(string)
}
//数学运算和位运算
function cypher(left,join,right)
{
left=todec(left,carry)
right=todec(right,carry)
if (join=="+")
return(decto(parseFloat(left)+parseFloat(right),carry))
if (join=="-")
return(decto(left-right,carry))
if (join=="*")
return(decto(left*right,carry))
if (join=="/" && right!=0)
return(decto(left/right,carry))
if (join=="%")
return(decto(left%right,carry))
if (join=="&")
return(decto(left&right,carry))
if (join=="|")
return(decto(left|right,carry))
if (join=="^")
return(decto(Math.pow(left,right),carry))
if (join=="x")
return(decto(left^right,carry))
if (join=="<")
return(decto(left<<right,carry))
alert("除数不能为零")
return(left)
}
//函数计算
function funcalc(fun,num)
{
with(Math)
{
if (fun=="pi")
return(PI)
if (fun=="e")
return(E)
if (fun=="abs")
return(abs(num))
if (fun=="ceil")
return(ceil(num))
if (fun=="round")
return(round(num))
if (fun=="floor")
return(floor(num))
if (fun=="deci")
return(num-floor(num))
if (fun=="ln" && num>0)
return(log(num))
if (fun=="exp")
return(exp(num))
if (fun=="log" && num>0)
return(log(num)*LOG10E)
if (fun=="expdec")
return(pow(10,num))
if (fun=="cube")
return(num*num*num)
if (fun=="cubt")
return(pow(num,1/3))
if (fun=="sqr")
return(num*num)
if (fun=="sqrt" && num>=0)
return(sqrt(num))
if (fun=="!")
return(factorial(num))
if (fun=="recip" && num!=0)
return(1/num)
if (fun=="dms")
return(dms(num))
if (fun=="deg")
return(deg(num))
if (fun=="~")
return(~num)
if (angle=="d")
{
if (fun=="sin")
return(sin(degressToRadians(num)))
if (fun=="cos")
return(cos(degressToRadians(num)))
if (fun=="tan")
return(tan(degressToRadians(num)))
if (fun=="arcsin" && abs(num)<=1)
return(radiansToDegress(asin(num)))
if (fun=="arccos" && abs(num)<=1)
return(radiansToDegress(acos(num)))
if (fun=="arctan")
return(radiansToDegress(atan(num)))
}
else
{
if (fun=="sin")
return(sin(num))
if (fun=="cos")
return(cos(num))
if (fun=="tan")
return(tan(num))
if (fun=="arcsin" && abs(num)<=1)
return(asin(num))
if (fun=="arccos" && abs(num)<=1)
return(acos(num))
if (fun=="arctan")
return(atan(num))
}
if (fun=="hypsin")
return((exp(num)-exp(0-num))*0.5)
if (fun=="hypcos")
return((exp(num)+exp(-num))*0.5)
if (fun=="hyptan")
return((exp(num)-exp(-num))/(exp(num)+exp(-num)))
if (fun=="ahypsin" | fun=="hypcos" | fun=="hyptan")
{
alert("对不起,公式还没有查到!")
return(num)
}
alert("超出函数定义范围")
return(num)
}
}
function factorial(n)
{
n=Math.abs(parseInt(n))
var fac=1
for (;n>0;n-=1)
fac*=n
return(fac)
}
function dms(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor(60*(n-d))
var s=(n-d)*60-m
}
var dms=d+m/100+s*0.006
if (neg)
dms=-dms
return(dms)
}
function deg(n)
{
var neg=(n<0)
with(Math)
{
n=abs(n)
var d=floor(n)
var m=floor((n-d)*100)
var s=(n-d)*100-m
}
var deg=d+m/60+s/36
if (neg)
deg=-deg
return(deg)
}
function degressToRadians(degress)
{
return(degress*Math.PI/180)
}
function radiansToDegress(radians)
{
return(radians*180/Math.PI)
}
//界面
//-->
</SCRIPT>
<!--written by GoldHuman li hai--><!--2000.8-->
<META content="Microsoft FrontPage 4.0" name=GENERATOR></HEAD>
<BODY>
<DIV align=center>
<FORM name=calc>
<TABLE height=250 width=500 border=1>
<TBODY>
<TR>
<TD height=50>
<TABLE width=500>
<TBODY>
<TR>
<TD></TD>
<TD>
<DIV align=center><INPUT readOnly size=40 value=0 name=display> </DIV></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD>
<TABLE width=500>
<TBODY>
<TR>
<TD width=290><INPUT onclick=inputChangCarry(16) type=radio name=carry> 十六进制 <INPUT onclick=inputChangCarry(10) type=radio CHECKED name=carry> 十进制 <INPUT onclick=inputChangCarry(8) type=radio name=carry> 八进制 <INPUT onclick=inputChangCarry(2) type=radio name=carry> 二进制 </TD>
<TD></TD>
<TD width=135><INPUT onclick="inputChangAngle('d')" type=radio CHECKED value=d name=angle> 角度制 <INPUT onclick="inputChangAngle('r')" type=radio value=r name=angle> 弧度制 </TD></TR></TBODY></TABLE>
<TABLE width=500>
<TBODY>
<TR>
<TD width=170><INPUT onclick=inputshift() type=checkbox name=shiftf>上档功能 <INPUT onclick=inputshift() type=checkbox name=hypf>双曲函数 </TD>
<TD><INPUT style="BACKGROUND-COLOR: lightgrey" readOnly size=3 name=bracket> <INPUT style="BACKGROUND-COLOR: lightgrey" readOnly size=3 name=memory> <INPUT style="BACKGROUND-COLOR: lightgrey" readOnly size=3 name=operator> </TD>
<TD width=183><INPUT style="COLOR: red" onclick=backspace() type=button value=" 退格 "> <INPUT style="COLOR: red" onclick="document.calc.display.value = 0 " type=button value=" 清屏 "> <INPUT style="COLOR: red" onclick=clearall() type=button value=" 全清"> </TD></TR></TBODY></TABLE>
<TABLE width=500>
<TBODY>
<TR>
<TD>
<TABLE>
<TBODY>
<TR align=middle>
<TD><INPUT style="COLOR: blue" onclick="inputfunction('pi','pi')" type=button value=" PI " name=pi> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputfunction('e','e')" type=button value=" E " name=e> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('dms','deg')" type=button value=d.ms name=bt> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: #ff00ff" onclick=addbracket() type=button value=" ( "> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick=disbracket() type=button value=" ) "> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('ln','exp')" type=button value=" ln " name=ln> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputtrig('sin','arcsin','hypsin','ahypsin')" type=button value="sin " name=sin> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="operation('^',7)" type=button value="x^y "> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('log','expdec')" type=button value="log " name=log> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputtrig('cos','arccos','hypcos','ahypcos')" type=button value="cos " name=cos> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('cube','cubt')" type=button value="x^3 " name=cube> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('!','!')" type=button value=" n! "> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputtrig('tan','arctan','hyptan','ahyptan')" type=button value="tan " name=tan> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('sqr','sqrt')" type=button value="x^2 " name=sqr> </TD>
<TD><INPUT style="COLOR: #ff00ff" onclick="inputfunction('recip','recip')" type=button value="1/x "> </TD></TR></TBODY></TABLE></TD>
<TD width=30></TD>
<TD>
<TABLE>
<TBODY>
<TR>
<TD><INPUT style="COLOR: red" onclick=putmemory() type=button value=" 储存 "> </TD></TR>
<TR>
<TD><INPUT style="COLOR: red" onclick=getmemory() type=button value=" 取存 "> </TD></TR>
<TR>
<TD><INPUT style="COLOR: red" onclick=addmemory() type=button value=" 累存 "> </TD></TR>
<TR>
<TD><INPUT style="COLOR: red" onclick=multimemory() type=button value=" 积存 "> </TD></TR>
<TR>
<TD height=33><INPUT style="COLOR: red" onclick=clearmemory() type=button value=" 清存 "> </TD></TR></TBODY></TABLE></TD>
<TD width=30></TD>
<TD>
<TABLE>
<TBODY>
<TR align=middle>
<TD><INPUT style="COLOR: blue" onclick="inputkey('7')" type=button value=" 7 " name=k7> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('8')" type=button value=" 8 " name=k8> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('9')" type=button value=" 9 " name=k9> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('/',6)" type=button value=" / "> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('%',6)" type=button value=取余> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('&',3)" type=button value=" 与 "> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: blue" onclick="inputkey('4')" type=button value=" 4 " name=k4> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('5')" type=button value=" 5 " name=k5> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('6')" type=button value=" 6 " name=k6> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('*',6)" type=button value=" * "> </TD>
<TD><INPUT style="COLOR: red" onclick="inputfunction('floor','deci')" type=button value=取整 name=floor> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('|',1)" type=button value=" 或 "> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: blue" onclick="inputkey('1')" type=button value=" 1 "> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('2')" type=button value=" 2 " name=k2> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('3')" type=button value=" 3 " name=k3> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('-',5)" type=button value=" - "> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('<',4)" type=button value=左移> </TD>
<TD><INPUT style="COLOR: red" onclick="inputfunction('~','~')" type=button value=" 非 "> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: blue" onclick="inputkey('0')" type=button value=" 0 "> </TD>
<TD><INPUT style="COLOR: blue" onclick=changeSign() type=button value=+/-> </TD>
<TD><INPUT style="COLOR: blue" onclick="inputkey('.')" type=button value=" . " name=kp> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('+',5)" type=button value=" + "> </TD>
<TD><INPUT style="COLOR: red" onclick=result() type=button value=" = "> </TD>
<TD><INPUT style="COLOR: red" onclick="operation('x',2)" type=button value=异或> </TD></TR>
<TR align=middle>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('a')" type=button value=" A " name=ka> </TD>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('b')" type=button value=" B " name=kb> </TD>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('c')" type=button value=" C " name=kc> </TD>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('d')" type=button value=" D " name=kd> </TD>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('e')" type=button value=" E" name=ke> </TD>
<TD><INPUT style="COLOR: blue" disabled onclick="inputkey('f')" type=button value=" F" name=kf> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM></DIV><%referer=Request.ServerVariables ("HTTP_REFERER")%>
<!--结束 -->
『拾』 Delphi7.0的计算器代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, Menus;
type
TForm1 = class(TForm)
Edit1: TEdit;
Panel1: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
SpeedButton15: TSpeedButton;
SpeedButton16: TSpeedButton;
SpeedButton17: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton18: TSpeedButton;
SpeedButton19: TSpeedButton;
SpeedButton20: TSpeedButton;
SpeedButton21: TSpeedButton;
SpeedButton5: TSpeedButton;
MainMenu1: TMainMenu;
zhua1: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
SpeedButton22: TSpeedButton;
N4: TMenuItem;
procere SpeedButton20Click(Sender: TObject);
procere SpeedButton1Click(Sender: TObject);
procere SpeedButton2Click(Sender: TObject);
procere SpeedButton3Click(Sender: TObject);
procere SpeedButton4Click(Sender: TObject);
procere SpeedButton6Click(Sender: TObject);
procere SpeedButton7Click(Sender: TObject);
procere SpeedButton13Click(Sender: TObject);
procere SpeedButton12Click(Sender: TObject);
procere SpeedButton14Click(Sender: TObject);
procere SpeedButton15Click(Sender: TObject);
procere SpeedButton17Click(Sender: TObject);
procere SpeedButton5Click(Sender: TObject);
procere SpeedButton19Click(Sender: TObject);
procere SpeedButton11Click(Sender: TObject);
procere SpeedButton18Click(Sender: TObject);
procere SpeedButton21Click(Sender: TObject);
procere SpeedButton16Click(Sender: TObject);
procere N1Click(Sender: TObject);
procere SpeedButton22Click(Sender: TObject);
procere N2Click(Sender: TObject);
procere FormCreate(Sender: TObject);
procere N4Click(Sender: TObject);
procere Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procere Edit1KeyPress(Sender: TObject; var Key: Char);
private
//将窗体变量放置在这里也可以,这样如果有
//Form2就无法访问
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
flag : Integer =0;
flag1: Integer =0; // 是否复位的标记
flag3: Integer =0; //小数点的标记
Temp1: string = '';
Temp2: real=0; //注意变量的定义
implementation
{$R *.dfm}
procere TForm1.SpeedButton20Click(Sender: TObject);
begin
if SpeedButton20.Caption = '关闭' then
begin
SpeedButton20.Caption := '打开' ;
SpeedButton20.Font.Color := clGreen
end
else
begin
SpeedButton20.Caption := '关闭';
SpeedButton20.Font.Color := clSilver
end;
end;
procere TForm1.SpeedButton1Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1=5 then Edit1.Text := '';
if SpeedButton20.Caption = '打开' then
begin
Edit1.Text := Edit1.text+'1';flag1 := 0;
end
end;
procere TForm1.SpeedButton2Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text :='';
if SpeedButton20.Caption = '打开' then
begin
Edit1.Text := Edit1.text+'2'; flag1 := 0;
end;
end;
procere TForm1.SpeedButton3Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption='打开' then
begin
Edit1.Text := Edit1.text+'3'; flag1:=0;
end;
end;
procere TForm1.SpeedButton4Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption='打开' then
begin
Edit1.Text := Edit1.text+'4'; flag1 := 0;
end;
end;
procere TForm1.SpeedButton6Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption='打开' then
begin
Edit1.Text:=Edit1.text+'5'; flag1:=0;
end;
end;
procere TForm1.SpeedButton7Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption = '打开' then
begin
Edit1.Text := Edit1.text+'6'; flag1:=0;
end;
end;
procere TForm1.SpeedButton13Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption = '打开' then
begin
Edit1.Text := Edit1.text+'7'; flag1 := 0;
end;
end;
procere TForm1.SpeedButton12Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption='打开' then
begin
Edit1.Text:=Edit1.text+'8'; flag1:=0;
end;
end;
procere TForm1.SpeedButton14Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack; //为每个Button恢复颜色 目的是区分数据是结果还是参加数
if flag1=5 then Edit1.Text := '';
if SpeedButton20.Caption='打开' then
begin
Edit1.Text := Edit1.text+'9'; flag1 := 0;
end;
end;
procere TForm1.SpeedButton15Click(Sender: TObject);
begin
Edit1.Font.Color := clBlack;
if flag1 = 5 then Edit1.Text := '';
if SpeedButton20.Caption = '打开' then
begin
Edit1.Text := Edit1.text+'0'; flag1 := 0;
end;
end;
procere TForm1.SpeedButton17Click(Sender: TObject);
begin
Edit1.Clear;
flag := 0;
flag1 := 5; // 是否复位的标记
flag3 :=0; //小数点的标记
Temp1 := '';
Temp2 :=0; //注意变量的定义
end;
procere TForm1.SpeedButton5Click(Sender: TObject);
begin
Edit1.Font.Color := Clgreen; //设置输入颜色
if (edit1.Text<>'+') and (edit1.Text<>'-')and (edit1.Text<>'*') and (edit1.Text<>'/')
and(edit1.text<>'')
then
begin
try //仅仅作为实验,记住使用的格式
case flag of //切记case 不支持字符型
1 : Temp2 := StrTofloat(Temp1)+StrTofloat(Edit1.text) ;
2 : Temp2 := StrTofloat(Temp1)-StrTofloat(Edit1.text) ;
3 : Temp2 := StrTofloat(Temp1)*StrTofloat(Edit1.text) ;
4 : begin
if StrTofloat(edit1.text)<>0 then Temp2 := StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
Edit1.Font.Color:=clLime;
showmessage('错误!除数不能够为0!');
Edit1.Font.Color:=clblack;
end;
end;
else
Temp2:=StrToFloat(Edit1.text);
end;
except
ShowMessage('错误!您输入的数据过大');
Form1.close;
end;
Temp1 := FloatToStr(Temp2);
if edit1.Font.Color=clblack then
begin
Temp1:=FloatToStr(Temp2);
Edit1.Text := Temp1;
flag1 := 5;
flag := 0;
flag3 := 0;
end ;
if edit1.Font.Color=clgreen then
begin
flag := 1;
flag1 := 5;
Edit1.Text := '+';
flag3 := 0;
end;
end;
end;
procere TForm1.SpeedButton19Click(Sender: TObject);
begin
Edit1.Font.Color := Clgreen;
if (edit1.Text<>'+') and (edit1.Text<>'-')and (edit1.Text<>'*') and (edit1.Text<>'/')and(edit1.text<>'')
then //当前里面的字符为 + -* / 不能够进行运算
begin
try
case flag of //切记case 不支持字符型
1 : Temp2 := StrTofloat(Temp1)+StrTofloat(Edit1.text) ;
2 : Temp2 := StrTofloat(Temp1)-StrTofloat(Edit1.text) ;
3 : Temp2 := StrTofloat(Temp1)*StrTofloat(Edit1.text) ;
4 :
begin
if StrTofloat(edit1.text)<>0 then Temp2 := StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
Edit1.Font.Color:=clLime;
showmessage('错误!除数不能够为0!');
Edit1.Font.Color:=clblack;
end;
end;
else
Temp2:=StrToFloat(Edit1.text);
end;
except
ShowMessage('错误!您输入的数据过大');
Form1.close;
end;
Temp1 := FloatToStr(Temp2);
if edit1.Font.Color=clblack then
begin
Temp1:=FloatToStr(Temp2);
Edit1.Text := Temp1;
flag1 := 5;
flag := 0;
flag3 := 0;
end ;
if edit1.Font.Color=clgreen then
begin
flag := 2;
flag1 := 5;
Edit1.Text := '-';
flag3 := 0;
end;
end;
end;
procere TForm1.SpeedButton11Click(Sender: TObject);
begin
Edit1.Font.Color:=Clgreen;
if (edit1.Text<>'+') and (edit1.Text<>'-')and (edit1.Text<>'*') and (edit1.Text<>'/')and(edit1.text<>'') then
begin
try
case flag of //切记case 不支持字符型
1 : Temp2 :=StrTofloat(Temp1)+StrTofloat(Edit1.text) ;
2 : Temp2 := StrTofloat(Temp1)-StrTofloat(Edit1.text) ;
3 : Temp2 := StrTofloat(Temp1)*StrTofloat(Edit1.text) ;
4 : begin
if StrTofloat(edit1.text)<>0 then Temp2:=StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
edit1.Font.Color:=clLime;
showmessage('错误!除数不能够为0!');
edit1.Font.Color:=clblack;
end;
end;
else
Temp2 := StrToFloat(Edit1.text);
end;
except
ShowMessage('错误!您输入的数据过大');
Form1.close;
end;
Temp1 := FloatToStr(Temp2);
if edit1.Font.Color=clblack then
begin
Temp1:=FloatToStr(Temp2);
Edit1.Text := Temp1;
flag1 := 5;
flag := 0;
flag3 := 0;
end ;
if edit1.Font.Color=clgreen then
begin
flag := 3;
flag1 := 5;
Edit1.Text := '*';
flag3 := 0;
end;
end;
end;
procere TForm1.SpeedButton18Click(Sender: TObject);
begin
Edit1.Font.Color := Clgreen;
if (edit1.Text<>'+') and (edit1.Text<>'-')and (edit1.Text<>'*') and (edit1.Text<>'/')
and (edit1.text<>'') then
begin
try
case flag of //切记case 不支持字符型
1 : Temp2 := StrTofloat(Temp1)+StrTofloat(Edit1.text) ;
2 : Temp2 := StrTofloat(Temp1)-StrTofloat(Edit1.text) ;
3 : Temp2 := StrTofloat(Temp1)*StrTofloat(Edit1.text) ;
4 : begin
if StrTofloat(edit1.text)<>0 then Temp2 := StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
edit1.Font.Color:=clLime;
showmessage('错误!除数不能够为0!');
edit1.Font.Color:=clblack;
end;
end;
else
Temp2 := StrToFloat(Edit1.text);
end;
except
ShowMessage('错误!您输入的数据过大');
Form1.close;
end;
Temp1 := FloatToStr(Temp2);
if edit1.Font.Color=clblack then
begin
Temp1:=FloatToStr(Temp2);
Edit1.Text := Temp1;
flag1 := 5;
flag := 0;
flag3 := 0;
end ;
if edit1.Font.Color=clgreen then
begin
flag := 4;
flag1 := 5;
Edit1.Text := '/';
flag3 := 0;
end;
end;
end;
procere TForm1.SpeedButton21Click(Sender: TObject);
begin
if messagedlg('是否退出?',mtconfirmation,[Mbyes,Mbno],0) = mryes then
close;
end;
procere TForm1.SpeedButton16Click(Sender: TObject);
begin
if flag1<>5 then
begin
try
case flag of //切记case 不支持字符型
1 : Temp2 := StrTofloat(Temp1)+StrTofloat(Edit1.text) ;
2 : Temp2 := StrTofloat(Temp1)-StrTofloat(Edit1.text) ;
3 : Temp2 := StrTofloat(Temp1)*StrTofloat(Edit1.text) ;
4 : begin
if StrTofloat(edit1.text)<>0 then Temp2:=StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
Edit1.Font.Color:=ClLime;
showmessage('错误!除数不能够为0!');
end;
end;
else
Temp2:=StrToFloat(Edit1.Text); //如果直接按=号,那么显示第一个数
//即把第一个数赋给第二个数
end;
except
ShowMessage('错误!您输入的数据过大');
Form1.close;
end;
flag:=0;
if Edit1.Font.Color=ClLime then Edit1.Font.Color := clBlack
else Edit1.Font.Color := clred ;
Edit1.Text:=FloatToStr(Temp2);
end;
flag1 := 5;
flag3 := 0;
end;
procere TForm1.N1Click(Sender: TObject);
begin
SpeedButton20.Caption := '打开';
N3.Caption := '状态/on'
end;
procere TForm1.SpeedButton22Click(Sender: TObject);
begin
Edit1.Font.Color := ClBlack;
if flag1 = 5 then //出现结果指点点小数点 会置0,避免这个情况先清空
// 然后设置 flag1:=0; 这样数字可以跟着后面输入
begin
Edit1.Text := '';
flag1 := 0;
end;
if (SpeedButton20.Caption='打开') and ( flag3=0) then
begin
if Edit1.Text = '' then
Edit1.Text := '0'+'.'+Edit1.text //如果直接点小数点的BUTTON 则在前面加0
else
Edit1.Text := Edit1.text+'.';
end;
Inc(flag3,1); //统计小数、点的个数
// 注意可以用inc(flag3,1)每次 加1 inc(flag3,1)每次加5
//Dec (flag,1)是减减1
end;
procere TForm1.N2Click(Sender: TObject);
begin
SpeedButton20.Caption := '关闭' ;
N3.Caption := '状态/off';
end;
procere TForm1.FormCreate(Sender: TObject);
begin
N3.Caption := '状态/on';
flag1:=5;
end;
procere TForm1.N4Click(Sender: TObject);
begin
close;
end;
procere TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = VK_RETURN then SpeedButton16.Click; // VK_RETURN为ENTER的虚拟值
//还有其他方法可以实现
end;
procere TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case key of
'1' : SpeedButton1.Click;
'2' : SpeedButton2.Click;
'3' : SpeedButton3.Click;
'4' : SpeedButton4.Click;
'5' : SpeedButton6.Click;
'6' : SpeedButton7.Click;
'7' : SpeedButton13.Click;
'8' : SpeedButton12.Click;
'9' : SpeedButton14.Click;
'0' : SpeedButton15.Click;
'.' : SpeedButton22.Click;
'+' : SpeedButton5.Click;
'-' : SpeedButton19.Click;
'*' : SpeedButton11.Click;
'/' : SpeedButton18.Click;
end;
end;
end.