Decred force calculator
POW: full name of proof of work
pos: proof of stake
both of them are the consensus mechanism of blockchain and the bookkeeping method of digital currency
the difference is:
1. POW mechanism: workload proof mechanism, that is, the proof of workload, is the requirement that must be met when generating a new transaction information (that is, a new block) to be added to the blockchain. In the blockchain network based on workload proof mechanism, the ability of nodes to obtain the correct numerical solution to generate blocks by calculating the numerical solution of random hash hash is the specific performance of node computing power
POS mechanism: the proof of rights and interests requires the certifier to provide a certain amount of ownership of cryptocurrency. The operation mode of the proof of rights and interests mechanism is that when creating a new block, the miners need to create a "currency right" transaction, and the transaction will send some coins to the miners themselves according to the preset proportion. According to the proportion and time of token owned by each node, the equity proof mechanism reces the mining difficulty of nodes proportionally according to the algorithm, so as to speed up the speed of searching for random numbersextended materials:
the concept of bitcoin was first proposed by Nakamoto in 2009. According to Nakamoto's ideas, the open source software and the P2P network on it were designed and released. Bitcoin is a kind of P2P digital currency. Point to point transmission means a decentralized payment system
unlike most currencies, bitcoin does not rely on specific currency institutions. It is generated by a large number of calculations based on specific algorithms. Bitcoin economy uses the distributed database composed of many nodes in the whole P2P network to confirm and record all transactions, and uses the design of cryptography to ensure the security of all aspects of currency circulation. The decentralized nature and algorithm of P2P can ensure that it is impossible to artificially manipulate the value of bitcoin through mass proction
看看我写得把,还不错,楼主给我追加点分吧
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);
}
}
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Buttons, Menus;< br />
type
TForm1 = class(TForm)
Edit1: TEdit;< br /> Panel1: TPanel;< br /> SpeedButton1: TSpeedButton;< br /> SpeedButton2: TSpeedButton;< br /> SpeedButton3: TSpeedButton;< br /> SpeedButton4: TSpeedButton;< br /> SpeedButton6: TSpeedButton;< br /> SpeedButton7: TSpeedButton;< br /> SpeedButton8: TSpeedButton;< br /> SpeedButton9: TSpeedButton;< br /> SpeedButton10: TSpeedButton;< br /> SpeedButton12: TSpeedButton;< br /> SpeedButton13: TSpeedButton;< br /> SpeedButton14: TSpeedButton;< br /> SpeedButton15: TSpeedButton;< br /> SpeedButton16: TSpeedButton;< br /> SpeedButton17: TSpeedButton;< br /> SpeedButton11: TSpeedButton;< br /> SpeedButton18: TSpeedButton;< br /> SpeedButton19: TSpeedButton;< br /> SpeedButton20: TSpeedButton;< br /> SpeedButton21: TSpeedButton;< br /> SpeedButton5: TSpeedButton;< br /> MainMenu1: TMainMenu;< br /> zhua1: TMenuItem;< br /> N1: TMenuItem;< br /> N2: TMenuItem;< br /> N3: TMenuItem;< br /> SpeedButton22: TSpeedButton;< br /> N4: TMenuItem;< br /> procere SpeedButton20Click(Sender: TObject);< br /> procere SpeedButton1Click(Sender: TObject);< br /> procere SpeedButton2Click(Sender: TObject);< br /> procere SpeedButton3Click(Sender: TObject);< br /> procere SpeedButton4Click(Sender: TObject);< br /> procere SpeedButton6Click(Sender: TObject);< br /> procere SpeedButton7Click(Sender: TObject);< br /> procere SpeedButton13Click(Sender: TObject);< br /> procere SpeedButton12Click(Sender: TObject);< br /> procere SpeedButton14Click(Sender: TObject);< br /> procere SpeedButton15Click(Sender: TObject);< br /> procere SpeedButton17Click(Sender: TObject);< br /> procere SpeedButton5Click(Sender: TObject);< br /> procere SpeedButton19Click(Sender: TObject);< br /> procere SpeedButton11Click(Sender: TObject);< br /> procere SpeedButton18Click(Sender: TObject);< br /> procere SpeedButton21Click(Sender: TObject);< br /> procere SpeedButton16Click(Sender: TObject);< br /> procere N1Click(Sender: TObject);< br /> procere SpeedButton22Click(Sender: TObject);< br /> procere N2Click(Sender: TObject);< br /> procere FormCreate(Sender: TObject);< br /> procere N4Click(Sender: TObject);< br /> procere Edit1KeyDown(Sender: TObject; var Key: Word;< br /> Shift: TShiftState);< br /> procere Edit1KeyPress(Sender: TObject; var Key: Char);< <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<22222223601;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>
{Public declarations}
end;< br />
var
Form1: TForm1;< br />flag: Integer =0;< br />flag1: Integer =0; //
flag3: Integer =0; // Temp1: string =%35;39;%35; 39;< br />Temp2: real=0; //
implementation
{$R *.dfm}
procere TForm1.SpeedButton20Click(Sender: TObject);< br />start
if SpeedButton20. Caption = 35; 39; Thirty-five? then
begin
SpeedButton20. Caption:35;39; (Translated with Google Translate) br /> SpeedButton20.Font.Color:= clGreen
end
else
begin
SpeedButton20. Caption:35; 39; [Chuckles] br /> SpeedButton20.Font.Color:= clSilver
end;< br />end;< br />
procere TForm1.SpeedButton1Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br />if flag1=5 then Edit1. 39;< br />if SpeedButton20. Caption =%35;39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 1&35;39; flag1:= 0;< br /> end
end;< br />
procere TForm1.SpeedButton2Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br />if flag1 = 5 then Edit1. Text:35;39;&35; 39;< br />if SpeedButton20. Caption =%35;39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 2&35;39; flag1:= 0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton3Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br />if flag1 = 5 then Edit1. Text:35;39;&35; 39;< br />if SpeedButton20.Caption=35; 39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 3&35;39; flag1:=0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton4Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20.Caption=35; 39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 4&35;39; flag1:= 0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton6Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20.Caption=35; 39; 3rd? then
begin
Edit1. Text:=Edit1.text+&35; 39; 5&35;39; flag1:=0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton7Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20. Caption =&35;39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 6&35;39; flag1:=0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton13Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20. Caption =&35;39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 7&35;39; flag1:= 0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton12Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20.Caption=35; 39; 3rd? then
begin
Edit1. Text:=Edit1.text+&35; 39; 8&35;39; flag1:=0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton14Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack; // "27599;" Button24674;"22797;" 39068;"20998;" 25454;"32467;" 265244;"36824;" 21442;" 39;< br /> if SpeedButton20.Caption=35; 39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 9&35;39; flag1:= 0;< br /> end;< br />end;< br />
procere TForm1.SpeedButton15Click(Sender: TObject);< br />start
Edit1.Font.Color:= clBlack;< br /> if flag1 = 5 then Edit1. Text:35;39;35; 39;< br /> if SpeedButton20. Caption =&35;39; 3rd? then
begin
Edit1. Text:= Edit1.text+&35; 39; 0&35;39; flag1:= 0; < br /> end;< br />end;< br />
procere TForm1.SpeedButton17Click(Sender: TObject);< br />start
Edit1.Clear;< br />flag:= 0;< br />flag1:= 5; //
flag3:=0; // "Temp1":="35;39;" "35"; "Temp1"; "Temp1"; "Temp1"; "Temp1"; 39;< br />Temp2:=0; //
end;< br />
procere TForm1.SpeedButton5Click(Sender: TObject);< br />start
Edit1.Font.Color:= Clgreen; // If (edit1.Text<) gt; 39;+&35; 39;) and (edit1.Text<& gt; 39;35; 39;) and (edit1.Text<& gt; 39; 39;) and (edit1.Text<& gt; 39? 39;)< br /> and(edit1.text<< gt; 39;35; 39;)< If you want to do this, then<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<19919981;2525255;<<<2525252525252525255;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if StrTofloat(edit1.text)<& gt; 0 then Temp2:= StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
Edit1.Font.Color:=clLime;< br /> showmessage(35; 39; Thirty-five? "38500;" 19981;"33021;" 228150;"0!" "35; 39;< br /> Edit1.Font.Color:=clblack;< br /> end;< br />
end;< br /> else
Temp2:=StrToFloat(Edit1.text);< br /> end;< br />
except
ShowMessage(35;39; Thirty-five? "36755;" "25454;" "36807;" "35;39;);< br /> Form1.close;< br /> end;< br /> Temp1:= FloatToStr(Temp2);< br /> if edit1.Font.Color=clblack then
begin
Temp1:=FloatToStr(Temp2);< br /> Edit1. Text:= Temp1;< br /> flag1:= 5;< br /> flag:= 0;< br /> flag3:= 0;< br /> end;< br /> if edit1.Font.Color=clgreen then
start
flag:= 1;< br /> flag1:= 5;< br /> Edit1. Text:35;39;+35; 39;< br /> flag3:= 0;< br /> end;< br />end;< br />end;< br />
procere TForm1.SpeedButton19Click(Sender: TObject);< br />start
Edit1.Font.Color:= Clgreen;< br />if (edit1.Text<& gt; 39;+&35; 39;) and (edit1.Text<& gt; 39;35; 39;) and (edit1.Text<& gt; 39; 39;) and (edit1.Text<& gt; 39? 39;) and(edit1.text<& gt; 39;35; 39;)< The /> <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>> (Temp1)+StrTofloat(Edit1.text);< br /> 2:Temp2:= StrTofloat(Temp1)-StrTofloat(Edit1.text);< br /> 3:Temp2:= StrTofloat(Temp1)*StrTofloat(Edit1.text);< br /> 4:
begin
if StrTofloat(edit1.text)<& gt; 0 then Temp2:= StrTofloat(Temp1)/StrTofloat(Edit1.text)
else
begin
Edit1.Font.Color:=clLime;< br /> showmessage(35; 39; Thirty-five? "38500;" 19981;"33021;" 228150;"0!" "35; 39;< br /> Edit1.Font.Color:=clblack;< br /> end;< br />
<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.$
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);
}
}
<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=="-")
