一个很简单的测试体重的java—applet小程序

 

import  java.awt. * ;
import  java.awt.event. * ;
public   class  weight {
 
public static void main(String args[]){
  
new Shu();
  }

}

class  Shu  extends  Frame {
  Label  out1
=new Label("你的身高");  
  TextField in1
=new TextField(8);
  Label  out5
=new Label("cm");
  Label  out2
=new Label("你的体重");
  TextField in2
=new TextField(8);
    Label  out6
=new Label("kg");
  
 
  
  Label  out3
=new Label("你的性别");
  CheckboxGroup cg
=new CheckboxGroup();
  Checkbox c1
=new Checkbox("男性",cg,true);
  Checkbox c2
=new Checkbox("女性",cg,true);
  
  Button b1
=new Button("计算");
  Button b2
=new Button("清空");
 
  Label  out4
=new Label("测试结果");
  TextField in3
=new TextField(25);




  Panel p1
=new Panel();
  Panel p2
=new Panel();
  Panel p3
=new Panel();
  


public Shu(){
  setLayout(
new GridLayout(3,1));
  p1.setLayout(
new FlowLayout());
  p2.setLayout(
new FlowLayout());
  p3.setLayout(
new FlowLayout());
  
  p1.add(out1); 
  p1.add(in1);
  p1.add(out5); 
  p1.add(out2);
  p1.add(in2);
  p1.add(out6); 

  p2.add(out3);
  p2.add(c1);
  p2.add(c2);
  p2.add(b1);
  p2.add(b2);
  
  p3.add(out4);
  p3.add(in3);
 
 add(p1);
 add(p2);
 add(p3);
 
 b1.addActionListener(
new b11());
 b2.addActionListener(
new b22());


 setSize(
400,300);
 show();
 addWindowListener(
new WindowAdapter(){
  
public void windowClosing(WindowEvent e)
{ System.exit(0); } }
);
                      }


class b11 implements ActionListener{
public void actionPerformed(ActionEvent e)
int x=Integer.valueOf(in1.getText()).intValue();
int y=Integer.valueOf(in2.getText()).intValue();
  
if(c2.getState())//
             {
      
if(y>(((x-100)*0.9-2.5)*0.9)&&y<(((x-100)*0.9-2.5)*1.1))    
                in3.setText(
"您的体重很标准,注意保持哦!!");
            
else if(y<(((x-100)*0.9-2.5)*0.9))    
                in3.setText(
"您的体重偏轻,要增加营养啊!!");
            
else if((((x-100)*0.9-2.5)*1.1)<y&&y<(((x-100)*0.9-2.5)*1.2))
                in3.setText(
"您的体重超重啦,要注意啦!!");
            
else if((((x-100)*0.9-2.5)*1.2)<y&&y<(((x-100)*0.9-2.5)*1.3))
                in3.setText(
"您有点轻度肥胖,该减肥了!!");
            
else if((((x-100)*0.9-2.5)*1.3)<y&&y<(((x-100)*0.9-2.5)*1.5))
                in3.setText(
"您中度肥胖,一定要减肥了!!");
            
else in3.setText("不敢相信世界上还有......!!");

             }
    
  

   


  
if(c1.getState())//
             {

             
if(y>((x-100)*0.9*0.9)&&y<((x-100)*0.9*1.1))    
                in3.setText(
"您的体重很标准,注意保持哦!!");
            
else if(y<((x-100)*0.9*0.9))    
                in3.setText(
"您的体重偏轻,要增加营养啊!!");
            
else if(((x-100)*0.9*1.1)<y&&y<((x-100)*0.9*1.2))
                in3.setText(
"您的体重超重啦,要注意啦!!");
            
else if(((x-100)*0.9*1.2)<y&&y<((x-100)*0.9*1.3))
                in3.setText(
"您有点轻度肥胖,该减肥了!!");
            
else if(((x-100)*0.9*1.3)<y&&y<((x-100)*0.9*1.5))
                in3.setText(
"您中度肥胖,一定要减肥了!!");
            
else in3.setText("不敢相信世界上还有......!!");
             }
    
    }

  }
 

    
class b22 implements ActionListener{
 
public void actionPerformed(ActionEvent e){
 in1.setText(
"");
 in2.setText(
"");
 in3.setText(
"");
      }


   }

}






  

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

chandra

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值