快来测测你的身材是否标准

此灵感来源于老婆手机上的一个程序,因此我也制作了一个测试身材是否肥胖的程序。感兴趣的就来测测吧。

这个程序是使用Adobe Flex Builder制作的,使用ActionScript 3.0编写。标准身材指数可以在源代码中找到。以下是程序的源代码。

BodyStandardTest类:

package {
import flash.display.*;
import flash.events.*;
import flash.text.*;

public class BodyStandardTest extends Sprite
{
var stageOutline:Shape;
var textfield1:TextField;
var tPleaseInputHeight:TextField;
var tInputHeight:TextField;
var tPleaseInputWeight:TextField;
var tInputWeight:TextField;
var tResult:TextField;

public function BodyStandardTest()
{
stage.scaleMode=StageScaleMode.NO_SCALE;
stageOutline=new Shape();
stageOutline.graphics.lineStyle(1);
stageOutline.graphics.drawRect(0,0,500,375);
addChild(stageOutline);
textfield1=new TextField;
textfield1.text=”输入你的身高和体重,以测试你的身材是否正常”;
textfield1.autoSize=TextFieldAutoSize.LEFT;
textfield1.selectable=false;
textfield1.y=10;
addChild(textfield1);
tPleaseInputHeight=new TextField();
tPleaseInputHeight.text=”请输入你的身高(cm):”;
tPleaseInputHeight.autoSize=TextFieldAutoSize.LEFT;
tPleaseInputHeight.selectable=false;
tPleaseInputHeight.y=40;;
addChild(tPleaseInputHeight);
tInputHeight=new TextField();
tInputHeight.x=120;
tInputHeight.y=40;
tInputHeight.width=300;
tInputHeight.height=15;
tInputHeight.type=TextFieldType.INPUT;
tInputHeight.border=true;
tInputHeight.background=true;
addChild(tInputHeight);
tPleaseInputWeight=new TextField();
tPleaseInputWeight.text=”请输入你的体重(kg):”;
tPleaseInputWeight.autoSize=TextFieldAutoSize.LEFT;
tPleaseInputWeight.selectable=false;
tPleaseInputWeight.y=80;
addChild(tPleaseInputWeight);
tInputWeight=new TextField();
tInputWeight.x=120;
tInputWeight.y=80;
tInputWeight.width=300;
tInputWeight.height=15;
tInputWeight.type=TextFieldType.INPUT;
tInputWeight.border=true;
tInputWeight.background=true;
addChild(tInputWeight);
var calculateMale:calculateButton=new calculateButton(“计算男人”);
calculateMale.x=140;
calculateMale.y=200;
var calculateFemale:calculateButton=new calculateButton(“计算女人”);
calculateFemale.x=260;
calculateFemale.y=200;
addChild(calculateMale);
addChild(calculateFemale);
tResult=new TextField();
tResult.x=50;
tResult.y=120;
tResult.selectable=false;
tResult.text=””;
tResult.autoSize=TextFieldAutoSize.LEFT;
addChild(tResult);
var note:TextField=new TextField();
note.selectable=false;
note.text=”仅供娱乐”;
note.autoSize=TextFieldAutoSize.LEFT;
var noteFormat:TextFormat=new TextFormat();
noteFormat.size=40;
noteFormat.color=0x333333;
note.setTextFormat(noteFormat);
note.x=stage.width/2-note.width/2;
note.y=300;
addChild(note);
calculateMale.addEventListener(MouseEvent.CLICK,calculateM);
calculateFemale.addEventListener(MouseEvent.CLICK,calculateF);
}
private function checkValue(textfield:TextField):Boolean{
var str:String=textfield.text;
for(var i:int=0;i<str.length;i++){
if(str.charCodeAt(i)>57||str.charCodeAt(i)<48){
return false;
}
trace(str.charCodeAt(i));
}
return true;
}
private function calculateM(e:MouseEvent):void{
if(checkValue(tInputHeight)&&checkValue(tInputWeight)){
var number1:Number=Number(tInputHeight.text);
var number2:Number=Number(tInputWeight.text);
if(number1/number2!=178/65){
tResult.text=”你的身材不标准”;
}else{
tResult.text=”恭喜!你是标准身材”;
}
}
}
private function calculateF(e:MouseEvent):void{
if(checkValue(tInputHeight)&&checkValue(tInputWeight)){
var number1:Number=Number(tInputHeight.text);
var number2:Number=Number(tInputWeight.text);
if(number1/number2!=160/48){
tResult.text=”你的身材不标准”;
}else{
tResult.text=”恭喜!你是标准身材”;
}
}
}
}
}

calculateButton类:

package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.*;
class calculateButton extends Sprite
{
var button:Sprite
public function calculateButton(inputText:String)
{
button=new Sprite();
button.graphics.lineStyle(1);
button.graphics.beginFill(0x999999,1);
button.graphics.drawRect(0,0,100,50);
button.graphics.endFill();
addChild(button);
var textfield:TextField=new TextField();
textfield.text=inputText;
textfield.selectable=false;
textfield.textColor=0xffffff;
var tFormat:TextFormat=new TextFormat();
tFormat.size=20;
textfield.setTextFormat(tFormat);
textfield.autoSize=TextFieldAutoSize.LEFT;
textfield.x=this.width/2-textfield.width/2;
textfield.y=this.height/2-textfield.height/2;
addChild(textfield);
this.addEventListener(MouseEvent.MOUSE_OVER,mouseRollOver);
this.addEventListener(MouseEvent.MOUSE_OUT,mouseRollOut);
}
private function mouseRollOver(e:MouseEvent):void{
button.graphics.lineStyle(1);
button.graphics.beginFill(0x666666,1);
button.graphics.drawRect(0,0,100,50);
button.graphics.endFill();
}
private function mouseRollOut(e:MouseEvent):void{
button.graphics.lineStyle(1);
button.graphics.beginFill(0x999999,1);
button.graphics.drawRect(0,0,100,50);
button.graphics.endFill();
}
}
}