หัวข้อ: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่วยหน่อยครับ เริ่มหัวข้อโดย: narusaktoru ที่ 21 กันยายน 2011, 16:01:30 ปกติเครื่องคิดเลข พอ 1+1 ละเรากด + อีกทีมันจะผลลัพท์เป็น 2 เลย แต่ของผม มันต้องกด เท่ากับถึงจะขึ้นช่วยดูโค้ดให้หน่อยครับ
if (o==bn12){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=1; } else if (o==bn13){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=2; } else if (o==bn14){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=3; } else if (o==bn15){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=4; } if (o==bn16){ number2=Integer.parseInt(tf.getText()); if(add==1){ result=num1+number2; tf.setText(new Integer(result).toString()); } else if(add==2){ result=num1-number2; tf.setText(new Integer(result).toString()); } else if(add==3){ result=num1*number2; tf.setText(new Integer(result).toString()); } else if(add==4){ result=num1/number2; tf.setText(new Integer(result).toString()); } } } คือช่วยที่คำนวณครับ หัวข้อ: Re: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่Ū เริ่มหัวข้อโดย: smapan ที่ 21 กันยายน 2011, 16:06:37 Java script version
โค๊ด: <FORM NAME="Calc"> ถ้าของ Java version กดที่นี่เลย http://cseweb.ucsd.edu/~pmol/Projects/Scientific%20Calculator/calculator.java หัวข้อ: Re: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่วยหน่อยครับ เริ่มหัวข้อโดย: bonshington ที่ 21 กันยายน 2011, 19:19:56 มีง่ายกว่านี้อีกคับ
<script> function recalculate(node){ try{ var lastChar = node.value.substring(str.length-2, 1); var result = 0; if(isNAN(lastChar)) result = eval("(" node.value.substring(0, str.length-1) ")"); else result = eval("(" node.value ")"); document.getElementById("result").innerHTML = parseFloat(result); } catch(Error){} } </script> <body> <input id="calculator" type="text" onkeyup="recalculate(this)"/> <label id="result">0</label> </body> หัวข้อ: Re: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่วยหน่อยครับ เริ่มหัวข้อโดย: ppane2007 ที่ 21 กันยายน 2011, 19:42:09 เข้ามางง เพราะเขียนไม่เป็น :P
หัวข้อ: Re: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่วยหน่อยครับ เริ่มหัวข้อโดย: KhunHen ที่ 21 กันยายน 2011, 20:44:25 ปกติเครื่องคิดเลข พอ 1+1 ละเรากด + อีกทีมันจะผลลัพท์เป็น 2 เลย แต่ของผม มันต้องกด เท่ากับถึงจะขึ้นช่วยดูโค้ดให้หน่อยครับ if (o==bn12){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=1; } else if (o==bn13){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=2; } else if (o==bn14){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=3; } else if (o==bn15){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=4; } if (o==bn16){ number2=Integer.parseInt(tf.getText()); if(add==1){ result=num1+number2; tf.setText(new Integer(result).toString()); } else if(add==2){ result=num1-number2; tf.setText(new Integer(result).toString()); } else if(add==3){ result=num1*number2; tf.setText(new Integer(result).toString()); } else if(add==4){ result=num1/number2; tf.setText(new Integer(result).toString()); } } } คือช่วยที่คำนวณครับ if (o==bn12){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=1; o=bn16; } else if (o==bn13){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=2; o=bn16; } else if (o==bn14){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=3; o=bn16; } else if (o==bn15){ num1=Integer.parseInt(tf.getText()); tf.setText(""); add=4; o=bn16; } if (o==bn16){ number2=Integer.parseInt(tf.getText()); if(add==1){ result=num1+number2; tf.setText(new Integer(result).toString()); } else if(add==2){ result=num1-number2; tf.setText(new Integer(result).toString()); } else if(add==3){ result=num1*number2; tf.setText(new Integer(result).toString()); } else if(add==4){ result=num1/number2; tf.setText(new Integer(result).toString()); } } } ลองแบบนี้ดูครับ java ไม่ค่อยเก่งครับ แต่ดู code แล้ว คุณต้อง ส่งการทำงาน ให้เข้าไปในส่วนของ bn16 ด้วยครับ หัวข้อ: Re: เครื่องคิดเลขจาว่า ติดอยู่นิดเดียวช่วยหน่อยครับ เริ่มหัวข้อโดย: kuznetsova ที่ 21 กันยายน 2011, 21:37:46 กด ตัวเลขตรวจสอบตัวแปล frist
กด ตัวเลขครั้งแรก frist = true กด + - * / check ค่า fist ว่าเป็น true หรือป่าว ถ้าใช่ ให้คำนวน ผลลัพ งงไหม ผมก็งง :P คิด อัลกอ ดีดีครับ |