블로그 이미지
세피롯스

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

Tag

2010. 2. 17. 14:27 초보프로그래머만..


플렉스 처음으로 배워보고 간단하게 짜본 계산기이다.
어디 참고도 안되겠지만 이거라도 아쉬운(?)사람들을 위해..ㅠ(나같은사람)

[Calculator.mxml 파일소스]

 

 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12">
<mx:Script>
 <![CDATA[
  import mx.controls.Alert;
  var temp:Number = 0, total:Number = 0;
  var calc:String = "";
  var calcChk:Boolean = false; //+,-,*,/클릭후 숫자클릭시 초기화체크여부
  
  
  public function b_plus():void{
   temp = Number(show.text);
   calc = "plus";
   calcChk = true; //
  }
  public function b_minus():void{
   temp = Number(show.text);
   calc = "minus";
   calcChk = true;
  }
  public function b_gob():void{
   temp = Number(show.text);
   calc = "gob";
   calcChk = true;
  }
  public function b_divide():void{
   temp = Number(show.text);
   calc = "divide";
   calcChk = true;
  }
  public function b_equals():void{
   if(show.text != "" && calc != ""){
    if(calc == "plus"){
     total = temp + Number(show.text);
     show.text = String(total);
    }else if(calc == "minus"){
     total = temp - Number(show.text);
     show.text = String(total);
    }else if(calc == "gob"){
     total = temp * Number(show.text);
     show.text = String(total);
    }else if(calc == "divide"){
     total = temp / Number(show.text);
     show.text = String(total);
    }
   }
   
   //초기화
   temp = 0;
   calc = "";
  }
  public function chk(num:String):void{
   //숫자0먼저 누른후 다른숫자 눌럿을경우 0은 지우기
   if(show.text == "0"){
    show.text = num;
    return;
   }
   //+,-,*,/버튼을 누른후에 누르면 text창을 초기화
   if(calcChk == true){
    show.text = num;
    calcChk = false;
   }else{
    show.text = show.text + num; 
   }
  }
 ]]>
</mx:Script>
 <mx:Panel layout="absolute" title="계산기" width="310" x="100" height="301" y="100">
  <mx:Button x="37" y="124" label="4" id="a4" click="chk('4')"/>
  <mx:Button x="158" y="124" label="6" id="a6" click="chk('6')"/>
  <mx:Button x="225" y="124" label="-" fontSize="12" id="minus" click="b_minus()"/>
  <mx:Button x="225" y="219" label="/" id="divide" click="b_divide()"/>
  <mx:Button x="225" y="172" label="*" id="gob" click="b_gob()"/>
  <mx:Button x="225" y="83" label="+" id="plus" click="b_plus()"/>
  <mx:Button x="158" y="172" label="9" id="a9" click="chk('9')"/>
  <mx:Button x="98" y="172" label="8" id="a8" click="chk('8')"/>
  <mx:Button x="98" y="124" label="5" id="a5" click="chk('5')"/>
  <mx:Button x="37" y="172" label="7" id="a7" click="chk('7')"/>
  <mx:Button x="158" y="83" label="3" id="a3" click="chk('3')"/>
  <mx:Button x="37" y="219" label="0" id="a0" click="chk('0')"/>
  <mx:Button x="98" y="83" label="2" id="a2" click="chk('2')"/>
  <mx:Button x="37" y="83" label="1" id="a1" click="chk('1')"/>
  <mx:Button x="158" y="219" label="=" width="40" id="equals" click="b_equals()"/>
  <mx:TextInput x="38" y="53" id="show"  textAlign="right" width="227" text="0"/>
  <mx:Button x="98" y="219" label="C" click="show.text = '0'"/>
 </mx:Panel>
</mx:Application>


posted by 세피롯스