Applet calculator

Συζητήσεις για την Java

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
Dimitris_tHEO
Δημοσιεύσεις: 16
Εγγραφή: 19 Ιαν 2006 14:19

Applet calculator

Δημοσίευση από Dimitris_tHEO » 02 Απρ 2006 19:24

ΕΑΝ ΚΑΝΟ ADD 9 ΚΟΥΜΠΙΑ (ΤΟΥΣ ΑΡΙΘΜΟΥΣ) ΚΑΙ 4 (ΤΑ ΣΥΜΒΟΛΑ + - / *) ΠΩΣ ΜΠΟΡΟΥΜΕ ΝΑ ΥΛΟΠΟΙΗΣΟΥΜΕ ΤΟΝ ΚΩΣΙΚΑ ΜΕΣΑ ΣΤΗΝ

public void actionPerformed(ActionEvent e){
}

ΓΙΑ ΝΑ ΚΑΝΟΥΜΕ ΕΝΑΝ CALCULATOR

Άβαταρ μέλους
fiskilis
Honorary Member
Δημοσιεύσεις: 14093
Εγγραφή: 16 Νοέμ 2003 22:44
Τοποθεσία: Athens
Επικοινωνία:

Applet calculator

Δημοσίευση από fiskilis » 03 Απρ 2006 11:44

για παρε αυτον τον κωδικα και κανε τον htm
κατι τετοιο θες ??

<tbody>
</tbody>
</table>
<b>
<table height="60" cellSpacing="5" borderColorDark="#660000" cellPadding="1" width="50" bgColor="#f0e8c0" borderColorLight="#cc9966" border="2">
<tbody>
<tr>
<td align="middle" colSpan="3"><input size="24" value="0" name="ReadOut" WIDTH="100%"></td>
<td>&nbsp;</td>
<td><input onclick="Clear()" type="button" value=" C " name="btnClear"></td>
<td><input onclick="ClearEntry()" type="button" value=" CE " name="btnClearEntry"></td>
</tr>
<tr>
<td vAlign="top"><input onclick="NumPressed(7)" type="button" value=" 7 " name="btnSeven"></td>
<td vAlign="top"><input onclick="NumPressed(8)" type="button" value=" 8 " name="btnEight"></td>
<td vAlign="top"><input onclick="NumPressed(9)" type="button" value=" 9 " name="btnNine"></td>
<td vAlign="top">&nbsp;</td>
<td vAlign="top"><input onclick="Neg()" type="button" value=" +/- " name="btnNeg"></td>
<td vAlign="top">
<p><input onclick="Percent()" type="button" value=" % " name="btnPercent"></p>
</td>
</tr>
<tr>
<td><input onclick="NumPressed(4)" type="button" value=" 4 " name="btnFour"></td>
<td><input onclick="NumPressed(5)" type="button" value=" 5 " name="btnFive"></td>
<td><input onclick="NumPressed(6)" type="button" value=" 6 " name="btnSix"></td>
<td>&nbsp;</td>
<td align="middle"><input onclick="Operation('+')" type="button" value=" + " name="btnPlus"></td>
<td align="middle"><input onclick="Operation('-')" type="button" value=" - " name="btnMinus"></td>
</tr>
<tr>
<td><input onclick="NumPressed(1)" type="button" value=" 1 " name="btnOne"></td>
<td><input onclick="NumPressed(2)" type="button" value=" 2 " name="btnTwo"></td>
<td><input onclick="NumPressed(3)" type="button" value=" 3 " name="btnThree"></td>
<td>&nbsp;</td>
<td align="middle"><input onclick="Operation('*')" type="button" value=" * " name="btnMultiply"></td>
<td align="middle"><input onclick="Operation('/')" type="button" value=" / " name="btnDivide"></td>
</tr>
<tr>
<td><input onclick="NumPressed(0)" type="button" value=" 0 " name="btnZero"></td>
<td><input onclick="Decimal()" type="button" value=" . " name="btnDecimal"></td>
</b></font><b>
<td borderColorLight="#000000" borderColorDark="#ffffff" colSpan="3">
<p align="center"><font face="VERDANA, ARIAL, HELVETICA" size="2"><a target="_top" href="http://threeclicks.com">ThreeClicks.com</a></font></p>
</td>
<font face="verdana, arial, helvetica" size="2">
<td><input onclick="Operation('=')" type="button" value=" = " name="btnEquals"></td>
</tr>
</tbody>
</table></CENTER>
</font></b>
</form>
<font face="verdana, arial, helvetica" size="2"><script language="JavaScript">
<!--
// Module-level variables
var FKeyPad = document.Keypad;
var Accum = 0; // Previous number (operand) awaiting operation
var FlagNewNum = false; // Flag to indicate a new number (operand) is being entered
var PendingOp = ""; // Pending operation waiting for completion of second operand

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;
//alert( 'op' );
if (FlagNewNum && PendingOp != "=");
// User is hitting op keys repeatedly, so don't do anything
else
{
//alert( PendingOp );
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 ()
{
// Remove current number and reset state
FKeyPad.ReadOut.value = "0";
FlagNewNum = true;
}

function Clear ()
{
// Clear accumulator and pending operation, and clear display
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);
}

//-->
</script>

Dimitris_tHEO
Δημοσιεύσεις: 16
Εγγραφή: 19 Ιαν 2006 14:19

Applet calculator

Δημοσίευση από Dimitris_tHEO » 06 Απρ 2006 19:01

ΕΝΟΟΥΣΑ ΣΕ jAVA ΠΩΣ ΜΠΟΡΩ ΝΑ ΚΑΝΩ ΕΝΑΝ CALCULATOR. THANKS ΚΑΠΟΥ ΘΑ ΧΡΕΙΑΣΤΕΙ ΚΑΙ ΑΥΤΟ.ΕΝΤΕΛΕΙ ΤΟ ΒΡΗΚΑ ΠΩΣ ΓΙΝΕΤΑΙ

Άβαταρ μέλους
manolism
Super Moderator
Δημοσιεύσεις: 6652
Εγγραφή: 25 Ιαν 2004 16:01
Τοποθεσία: Wild West
Επικοινωνία:

Applet calculator

Δημοσίευση από manolism » 06 Απρ 2006 19:18

Δεν μας λες και εμάς... :roll:

Dimitris_tHEO
Δημοσιεύσεις: 16
Εγγραφή: 19 Ιαν 2006 14:19

Applet calculator

Δημοσίευση από Dimitris_tHEO » 08 Απρ 2006 17:25

ΔΕΝ ΠΙΣΤΕΥΩ ΝΑ ΕΙΝΑΙ ΚΑΙ Ο ΠΙΟ ΣΩΣΤΟΣ ΤΡΟΠΟΣ , ΜΟΝΟΣ ΜΟΥ ΤΟ ΕΚΑΝΑ . ΑΛΛΑ ΔΟΥΛΕΥΕΙ .

Κώδικας: Επιλογή όλων

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class calc extends Applet implements ActionListener&#123;
 TextField tf1;
 Button bt1,bt2,bt3,bt4,bt5,bt6,bt7,bt8,bt9,bt0,bts,btp,bte,btd,btac,btison;
 int num1,num2,sum,count;
 String a,s,s1;
 
public void init&#40;&#41;&#123;
//tf1.setBackground&#40;Color.yellow&#41;;
 setBackground&#40;Color.black&#41;;
 tf1=new TextField&#40;10&#41;;
 add&#40;tf1&#41;;
 bt7=new Button&#40;"7"&#41;;
 add&#40;bt7&#41;;
 bt7.addActionListener&#40;this&#41;;
 bt8=new Button&#40;"8"&#41;;
 add&#40;bt8&#41;;
 bt8.addActionListener&#40;this&#41;;
 bt9=new Button&#40;"9"&#41;;
 add&#40;bt9&#41;;
 bt4=new Button&#40;"4"&#41;;
 add&#40;bt4&#41;;
 bt4.addActionListener&#40;this&#41;;
 bt5=new Button&#40;"5"&#41;;
 add&#40;bt5&#41;;
 bt5.addActionListener&#40;this&#41;;
 bt6=new Button&#40;"6"&#41;;
 add&#40;bt6&#41;;
 bt6.addActionListener&#40;this&#41;;
 bt1=new Button&#40;"1"&#41;;
 add&#40;bt1&#41;;
 bt1.addActionListener&#40;this&#41;;
 bt2=new Button&#40;"2"&#41;;
 add&#40;bt2&#41;;
 bt2.addActionListener&#40;this&#41;;
 bt3=new Button&#40;"3"&#41;;
 add&#40;bt3&#41;;
 bt3.addActionListener&#40;this&#41;;
 bt9.addActionListener&#40;this&#41;;
 bt0=new Button&#40;"0"&#41;;
 add&#40;bt0&#41;;
 bt0.addActionListener&#40;this&#41;;

 bts=new Button&#40;"+"&#41;;
 add&#40;bts&#41;;
 bts.addActionListener&#40;this&#41;;
 btp=new Button&#40;"-"&#41;;
 add&#40;btp&#41;;
 btp.addActionListener&#40;this&#41;;
 bte=new Button&#40;"*"&#41;;
 add&#40;bte&#41;;
 bte.addActionListener&#40;this&#41;;
 btd=new Button&#40;"/"&#41;;
 add&#40;btd&#41;;
 btd.addActionListener&#40;this&#41;;
 btison=new Button&#40;"="&#41;;
 add&#40;btison&#41;;
 btison.addActionListener&#40;this&#41;;
 btac=new Button&#40;"AC"&#41;;
 add&#40;btac&#41;;
 btac.addActionListener&#40;this&#41;;

&#125;
public void actionPerformed&#40;ActionEvent e&#41;&#123;
Object source = e.getSource&#40;&#41;;

 s=e.getActionCommand&#40;&#41;;
 if &#40;s=="AC"&#41;&#123;
     num1=0;
     num2=0;
     sum=0;
     tf1.setText&#40;""&#41;;
 &#125;else if &#40;s== "1"&#41;&#123;
      		s1= tf1.getText&#40;&#41;;
    		s1= s1+ 1;
    		tf1.setText&#40;s1&#41;;
&#125; else if &#40;s=="2"&#41;&#123;
            s1= tf1.getText&#40;&#41;;
    		s1= s1+ 2;
    		tf1.setText&#40;s1&#41;;
  &#125;else if &#40;s== "3"&#41;&#123;
      		s1= tf1.getText&#40;&#41;;
    		s1= s1+ 3;
    		tf1.setText&#40;s1&#41;;
&#125; else if &#40;s=="4"&#41;&#123;
            s1= tf1.getText&#40;&#41;;
    		s1= s1+ 4;
    		tf1.setText&#40;s1&#41;;
  &#125;else if &#40;s== "5"&#41;&#123;
      		s1= tf1.getText&#40;&#41;;
    		s1= s1+ 5;
    		tf1.setText&#40;s1&#41;;
 &#125; else if &#40;s=="6"&#41;&#123;
            s1= tf1.getText&#40;&#41;;
    		s1= s1+ 6;
    		tf1.setText&#40;s1&#41;;
  &#125;else if &#40;s== "7"&#41;&#123;
      		s1= tf1.getText&#40;&#41;;
    		s1= s1+ 7;
    		tf1.setText&#40;s1&#41;;
 &#125; else if &#40;s=="8"&#41;&#123;
            s1= tf1.getText&#40;&#41;;
    		s1= s1+ 8;
    		tf1.setText&#40;s1&#41;;
  &#125;else if &#40;s== "9"&#41;&#123;
      		s1= tf1.getText&#40;&#41;;
    		s1= s1+ 9;
    		tf1.setText&#40;s1&#41;;
 &#125; else if &#40;s=="0"&#41;&#123;
            s1= tf1.getText&#40;&#41;;
    		s1= s1+ 0;
    		tf1.setText&#40;s1&#41;;
  &#125;else if &#40;s=="+"&#41;&#123;
	count=1;
 	a=tf1.getText&#40;&#41;;
 	num1=Integer.parseInt&#40;a&#41;;
 	tf1.setText&#40;""&#41;; 	
 &#125;else if &#40;s=="-"&#41;&#123;
        count=2;
 		a=tf1.getText&#40;&#41;;
 		num1=Integer.parseInt&#40;a&#41;;
 		tf1.setText&#40;""&#41;;
       &#125;else if &#40;s=="*"&#41;&#123;
       	      count=3;
 			  a=tf1.getText&#40;&#41;;
 			  num1=Integer.parseInt&#40;a&#41;;
 			  tf1.setText&#40;""&#41;; 
       		 &#125;else if &#40;s=="/"&#41;&#123;
                    count=4;
 			 	 	a=tf1.getText&#40;&#41;;
 			  		num1=Integer.parseInt&#40;a&#41;;
 			  		tf1.setText&#40;""&#41;;
       		 	   &#125;else if &#40;s=="="&#41;&#123;  //edo mpainoun oles oi ipolipes if
       		 	   	     if &#40;count==1&#41;&#123;
       		 	   	     a=tf1.getText&#40;&#41;;
 	                     num2=Integer.parseInt&#40;a&#41;;
           	   		     sum=num1+num2;
       		 	         s=Integer.toString&#40;sum&#41;;
                         tf1.setText&#40;s&#41;;
                         &#125;else if &#40;count==2&#41;&#123;
                               a=tf1.getText&#40;&#41;;
 	                  		   num2=Integer.parseInt&#40;a&#41;;
           	   		  		   sum=num1-num2;
       		 	      		   s=Integer.toString&#40;sum&#41;;
                     		   tf1.setText&#40;s&#41;;
                     		 &#125; 
                             else if &#40;count==3&#41;&#123;
                              a=tf1.getText&#40;&#41;;
 	                  		  num2=Integer.parseInt&#40;a&#41;;
           	   		  		  sum=num1*num2;
       		 	      		  s=Integer.toString&#40;sum&#41;;
                     		  tf1.setText&#40;s&#41;;
                              &#125;else if &#40;count==4&#41;&#123;
                              a=tf1.getText&#40;&#41;;
 	                  		  num2=Integer.parseInt&#40;a&#41;;
           	   		  		  sum=num1/num2;
       		 	      		  s=Integer.toString&#40;sum&#41;;
                     		  tf1.setText&#40;s&#41;;
                              &#125;  		 	   	      		 	   	 		 	   	
       		 
       		 	   	&#125;
&#125;
&#125;

Απάντηση

Επιστροφή στο “Java”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες