国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|JavaScript|易語言|

服務器之家 - 編程語言 - JAVA教程 - Java Swing實現簡單的體重指數(BMI)計算器功能示例

Java Swing實現簡單的體重指數(BMI)計算器功能示例

2021-03-04 10:21Hisom JAVA教程

這篇文章主要介紹了Java Swing實現簡單的體重指數(BMI)計算器功能,涉及Java Swing窗口組件布局、響應及數值運算相關操作技巧,需要的朋友可以參考下

本文實例講述了Java Swing實現簡單的體重指數(BMI)計算器功能。分享給大家供大家參考,具體如下:

BMI,Body Mass Index,身體質量指數,是用體重公斤數 除以 身高米數平方得出的,是目前國際上常用的衡量人體胖瘦程度以及是否健康的一個標準。

而本文通過運用Java Swing實現了一個簡單的BMI計算器。雖然現在網頁上也有相應的網頁應用,但是能夠做出這個計算器來,還是有點成就感的,希望自己以后做出更多比這個好的應用。

最終運行效果:

Java Swing實現簡單的體重指數(BMI)計算器功能示例

功能:可以選擇三個標準:中國、亞洲、WHO,計算結果稍有不同

計算公式:BMI = weight / (height*height)   即 體重公斤數 除以 身高米數平方

?
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package WeightIndex;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.regex.*;
public class WeightIndex extends JFrame {
 /**
  *
  */
 private static final long serialVersionUID = 1L;
 private JPanel contentPane;
 private JLabel titleLabel;
 private JPanel contentPanel;
 private JButton submitButton;
 private ButtonGroup bg;
 private JPanel sexPanel;
 private JRadioButton ChinaRadio;
 private JRadioButton AsiaRadio;
 private JRadioButton WHORadio;
 private JPanel whPanel;
 private JLabel heightLabel;
 private JLabel weightLabel;
 private JTextField heightText;
 private JTextField weightText;
 private JPanel consolePanel;
 private JLabel consoleLabel;
 private JTextField consoleText;
 private double weight;
 private double height;
 private double BMI;
 /**
  * Launch the application.
  */
 public static void main(String[] args) {
  EventQueue.invokeLater(new Runnable() {
   public void run() {
    try {
     WeightIndex frame = new WeightIndex();
     frame.pack();
     frame.setVisible(true);
    } catch (Exception e) {
     e.printStackTrace();
    }
   }
  });
 }
 /**
  * Create the frame.
  */
 public WeightIndex() {
  setTitle("服務器之家 - 身高體重指數計算器v1.0");
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setBounds(100, 100, 450, 300);
  //主容器
  contentPane = new JPanel();
  contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  contentPane.setLayout(new BorderLayout(0, 0));
  setContentPane(contentPane);
  //標題,主容器北
  titleLabel = new JLabel("身高體重指數計算器");
  titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
  contentPane.add(titleLabel, BorderLayout.NORTH);
  //存放選項的panel,主容器中
  contentPanel = new JPanel();
  contentPanel.setLayout(new BorderLayout());
  contentPane.add(contentPanel,BorderLayout.CENTER);
  //提交按鈕,主容器南
  submitButton = new JButton("計算");
  contentPane.add(submitButton, BorderLayout.SOUTH);
  //存放性別選擇的panel,選項北
  bg = new ButtonGroup();
  sexPanel = new JPanel();
  sexPanel.setLayout(new FlowLayout());
  contentPanel.add(sexPanel,BorderLayout.NORTH);
  ChinaRadio = new JRadioButton("中國標準");
  ChinaRadio.setSelected(true);
  AsiaRadio = new JRadioButton("亞洲標準");
  WHORadio = new JRadioButton("WHO(世界衛(wèi)生組織)標準");
  bg.add(ChinaRadio);
  bg.add(AsiaRadio);
  bg.add(WHORadio);
  sexPanel.add(ChinaRadio);
  sexPanel.add(AsiaRadio);
  sexPanel.add(WHORadio);
  //存放身高體重的panel,選項中
  whPanel = new JPanel();
  whPanel.setLayout(new FlowLayout());
  contentPanel.add(whPanel,BorderLayout.CENTER);
  heightLabel = new JLabel("身高(米/m):");
  weightLabel = new JLabel("體重(千克/kg):");
  heightText = new JTextField(10);
  heightText.setToolTipText("請輸入身高");
  weightText = new JTextField(10);
  weightText.setToolTipText("請輸入體重");
  whPanel.add(heightLabel);
  whPanel.add(heightText);
  whPanel.add(weightLabel);
  whPanel.add(weightText);
  //結果
  consolePanel = new JPanel();
  consolePanel.setLayout(new FlowLayout());
  consoleLabel = new JLabel("你的身體質量指數為:");
  consoleText = new JTextField(28);
  consoleText.setEditable(false);
  consolePanel.add(consoleLabel);
  consolePanel.add(consoleText);
  contentPanel.add(consolePanel,BorderLayout.SOUTH);
  submitButton.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent e) {
    String hstr = heightText.getText();
    String wstr = weightText.getText();
    Pattern pattern = Pattern.compile("^[0-9]+(.[0-9]+)?$");
    Matcher hisNum = pattern.matcher(hstr);
    Matcher wisNum = pattern.matcher(wstr);
    boolean acc = true;
    if( !hisNum.matches()|| !wisNum.matches()){
      acc = false;
    }
    if(acc)
    {
     height = Double.parseDouble(hstr);
     weight = Double.parseDouble(wstr);
     BMI = weight / (height*height);
     DecimalFormat df = new DecimalFormat("#.0");
     String out = "";
     if(ChinaRadio.isSelected())
     {
      if(BMI<18.5)
       out = "偏瘦,瘦骨嶙峋的,多吃點吧!";
      else if(BMI<23.9)
       out = "正常,棒棒噠!";
      else if(BMI<28)
       out = "偏胖,你胖你就運動減肥!";
      else if(BMI>=28)
       out = "肥胖,現在減肥來的及!";
      else
       out ="外星人派來的你哦,請重新輸入!";
     }
     else if(AsiaRadio.isSelected())
     {
      if(BMI<18.5)
       out = "偏瘦,瘦骨嶙峋的,多吃點吧!";
      else if(BMI<22.9)
       out = "正常,棒棒噠!";
      else if(BMI<24.9)
       out = "偏胖,你胖你就運動減肥!";
      else if(BMI<30)
       out = "肥胖,現在減肥來的及!";
      else if(BMI>=30)
       out = "重度肥胖,不是一般人,趕緊減肥吧!";
      else
       out ="外星人派來的你哦,請重新輸入!";
     }
     else
     {
      if(BMI<18.5)
       out = "偏瘦,瘦骨嶙峋的,多吃點吧!";
      else if(BMI<24.9)
       out = "正常,棒棒噠!";
      else if(BMI<29.9)
       out = "偏胖,你胖你就運動減肥!";
      else if(BMI<34.9)
       out = "肥胖,現在減肥來的及!";
      else if(BMI<39.9)
       out = "重度肥胖,不是一般人,趕緊減肥吧!";
      else if(BMI>=40)
       out = "極重度肥胖,那可能得去醫(yī)院看看咯!";
      else
       out ="外星人派來的你哦,請重新輸入!";
     }
     consoleText.setText("你的指數為:"+df.format(BMI)+",你的健康狀況為:"+out);
    }
   }
  });
 }
}

希望本文所述對大家java程序設計有所幫助。

原文鏈接:http://blog.csdn.net/u010992313/article/details/72083337

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 日韩中文字幕在线播放 | 日本久久久久 | 亚欧毛片| 国产黄色免费观看 | 国产一区二区高清在线 | 日韩免费在线观看视频 | 亚洲经典一区 | 男女中文字幕 | 久久人人爽爽爽人久久久 | 国产欧美精品一区二区三区四区 | 香蕉夜色 | 免费看黄a| 久久久久久这里只有精品 | 久久久网 | 亚洲精品欧洲精品 | 中文字幕在线三区 | 一区亚洲 | 国产一区二区三区 | 免费观看一区二区三区毛片软件 | 免费成人高清在线视频 | 欧美片网站免费 | 久久久久久久久久久免费 | 亚洲精品免费av | 91综合国产 | 国产人久久人人人人爽 | 日韩电影在线看 | 黄网站免费看 | 亚洲免费片 | 在线免费黄色 | 九色porny国模私拍av | 欧美在线不卡 | 视频一区二区三区在线观看 | 色噜噜狠狠一区二区三区狼国成人 | 精品久久中文字幕 | 色播开心网 | 韩国一区二区视频 | 国产97在线播放 | 国产视频中文字幕 | 一级电影在线观看 | 亚洲一区在线视频 | 91在线视频观看 |