求高手 编一个 JAVA 的计算器小程序 15
求高手编一个JAVA的计算器小程序,上课用~请发送到本人邮箱641310171@qq.com请高手留个号我给分...
求高手 编一个 JAVA 的计算器小程序 ,上课用~
请发送到 本 人邮箱 641310171@qq.com
请高手 留个号 我给分 展开
请发送到 本 人邮箱 641310171@qq.com
请高手 留个号 我给分 展开
1个回答
2010-04-13
展开全部
<FORM name="Keypad" action="">
<input name="ReadOut" type="Text" size=24 value="0" width=100%><br>
<input name="btnClear" type="Button" value=" C " onclick="Clear()">
<input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()">
<input name="btnEquals" type="Button" value=" = " onclick="Operation('=')">
<br>
<input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)">
<input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)">
<input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)">
<br>
<input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)">
<input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)">
<input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)"><br>
<input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)">
<input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)">
<input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)"><br>
<input name="btnPlus" type="Button" value=" + " onclick="Operation('+')">
<input name="btnMinus" type="Button" value=" - " onclick="Operation('-')">
<input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')"><br>
<input name="btnDivide" type="Button" value=" / " onclick="Operation('/')">
<input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)">
<input name="btnDecimal" type="Button" value=" . " onclick="Decimal()">
</B>
</FORM>
</CENTER>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FKeyPad = document.Keypad;
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
}
// End -->
</SCRIPT>
借鉴下
<input name="ReadOut" type="Text" size=24 value="0" width=100%><br>
<input name="btnClear" type="Button" value=" C " onclick="Clear()">
<input name="btnClearEntry" type="Button" value=" CE " onclick="ClearEntry()">
<input name="btnEquals" type="Button" value=" = " onclick="Operation('=')">
<br>
<input name="btnSeven" type="Button" value=" 7 " onclick="NumPressed(7)">
<input name="btnEight" type="Button" value=" 8 " onclick="NumPressed(8)">
<input name="btnNine" type="Button" value=" 9 " onclick="NumPressed(9)">
<br>
<input name="btnFour" type="Button" value=" 4 " onclick="NumPressed(4)">
<input name="btnFive" type="Button" value=" 5 " onclick="NumPressed(5)">
<input name="btnSix" type="Button" value=" 6 " onclick="NumPressed(6)"><br>
<input name="btnOne" type="Button" value=" 1 " onclick="NumPressed(1)">
<input name="btnTwo" type="Button" value=" 2 " onclick="NumPressed(2)">
<input name="btnThree" type="Button" value=" 3 " onclick="NumPressed(3)"><br>
<input name="btnPlus" type="Button" value=" + " onclick="Operation('+')">
<input name="btnMinus" type="Button" value=" - " onclick="Operation('-')">
<input name="btnMultiply" type="Button" value=" * " onclick="Operation('*')"><br>
<input name="btnDivide" type="Button" value=" / " onclick="Operation('/')">
<input name="btnZero" type="Button" value=" 0 " onclick="NumPressed(0)">
<input name="btnDecimal" type="Button" value=" . " onclick="Decimal()">
</B>
</FORM>
</CENTER>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var FKeyPad = document.Keypad;
var Accum = 0;
var FlagNewNum = false;
var PendingOp = "";
function NumPressed (Num) {
if (FlagNewNum) {
FKeyPad.ReadOut.value = Num;
FlagNewNum = false;
}
else {
if (FKeyPad.ReadOut.value == "0")
FKeyPad.ReadOut.value = Num;
else
FKeyPad.ReadOut.value += Num;
}
}
function Operation (Op) {
var Readout = FKeyPad.ReadOut.value;
if (FlagNewNum && PendingOp != "=");
else
{
FlagNewNum = true;
if ( '+' == PendingOp )
Accum += parseFloat(Readout);
else if ( '-' == PendingOp )
Accum -= parseFloat(Readout);
else if ( '/' == PendingOp )
Accum /= parseFloat(Readout);
else if ( '*' == PendingOp )
Accum *= parseFloat(Readout);
else
Accum = parseFloat(Readout);
FKeyPad.ReadOut.value = Accum;
PendingOp = Op;
}
}
function Decimal () {
var curReadOut = FKeyPad.ReadOut.value;
if (FlagNewNum) {
curReadOut = "0.";
FlagNewNum = false;
}
else
{
if (curReadOut.indexOf(".") == -1)
curReadOut += ".";
}
FKeyPad.ReadOut.value = curReadOut;
}
function ClearEntry () {
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}
function Clear () {
Accum = 0;
PendingOp = "";
ClearEntry();
}
function Neg () {
FKeyPad.ReadOut.value = parseFloat(FKeyPad.ReadOut.value) * -1;
}
function Percent () {
FKeyPad.ReadOut.value = (parseFloat(FKeyPad.ReadOut.value) / 100) * parseFloat(Accum);
}
// End -->
</SCRIPT>
借鉴下
参考资料: 另一位高手的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询