- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Java Swing实现简单的体重指数(BMI)计算器功能示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了Java Swing实现简单的体重指数(BMI)计算器功能。分享给大家供大家参考,具体如下:
BMI,Body Mass Index,身体质量指数,是用体重公斤数 除以 身高米数平方得出的,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准.
而本文通过运用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(世界卫生组织)标准"
);
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 =
"极重度肥胖,那可能得去医院看看咯!"
;
else
out =
"外星人派来的你哦,请重新输入!"
;
}
consoleText.setText(
"你的指数为:"
+df.format(BMI)+
",你的健康状况为:"
+out);
}
}
});
}
}
|
希望本文所述对大家java程序设计有所帮助.
原文链接:http://blog.csdn.net/u010992313/article/details/72083337 。
最后此篇关于Java Swing实现简单的体重指数(BMI)计算器功能示例的文章就讲到这里了,如果你想了解更多关于Java Swing实现简单的体重指数(BMI)计算器功能示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我正在努力实现以下目标, 假设我有字符串: ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ( z ) ( A ) ) ) ) ) 我想编写一个正则
给定: 1 2 3 4 5 6
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
大家好,我卡颂。 Svelte问世很久了,一直想写一篇好懂的原理分析文章,拖了这么久终于写了。 本文会围绕一张流程图和两个Demo讲解,正确的食用方式是用电脑打开本文,跟着流程图、Demo一
身份证为15位或者18位,15位的全为数字,18位的前17位为数字,最后一位为数字或者大写字母”X“。 与之匹配的正则表达式: ?
我们先来最简单的,网页的登录窗口; 不过开始之前,大家先下载jquery的插件 本人习惯用了vs2008来做网页了,先添加一个空白页 这是最简单的的做法。。。先在body里面插入 <
1、MySQL自带的压力测试工具 Mysqlslap mysqlslap是mysql自带的基准测试工具,该工具查询数据,语法简单,灵活容易使用.该工具可以模拟多个客户端同时并发的向服务器发出
前言 今天大姚给大家分享一款.NET开源(MIT License)、免费、简单、实用的数据库文档(字典)生成工具,该工具支持CHM、Word、Excel、PDF、Html、XML、Markdown等
Go语言语法类似于C语言,因此熟悉C语言及其派生语言( C++、 C#、Objective-C 等)的人都会迅速熟悉这门语言。 C语言的有些语法会让代码可读性降低甚至发生歧义。Go语言在C语言的
我正在使用快速将 mkv 转换为 mp4 ffmpeg 命令 ffmpeg -i test.mkv -vcodec copy -acodec copy new.mp4 但不适用于任何 mkv 文件,当
我想计算我的工作簿中的工作表数量,然后从总数中减去特定的工作表。我错过了什么?这给了我一个对象错误: wsCount = ThisWorkbook.Sheets.Count - ThisWorkboo
我有一个 perl 文件,用于查看文件夹中是否存在 ini。如果是,它会从中读取,如果不是,它会根据我为它制作的模板创建一个。 我在 ini 部分使用 Config::Simple。 我的问题是,如果
尝试让一个 ViewController 通过标准 Cocoa 通知与另一个 ViewController 进行通信。 编写了一个简单的测试用例。在我最初的 VC 中,我将以下内容添加到 viewDi
我正在绘制高程剖面图,显示沿路径的高程增益/损失,类似于下面的: Sample Elevation Profile with hand-placed labels http://img38.image
嗨,所以我需要做的是最终让 regStart 和 regPage 根据点击事件交替可见性,我不太担心编写 JavaScript 函数,但我根本无法让我的 regPage 首先隐藏。这是我的代码。请简单
我有一个非常简单的程序来测量一个函数花费了多少时间。 #include #include #include struct Foo { void addSample(uint64_t s)
我需要为 JavaScript 制作简单的 C# BitConverter。我做了一个简单的BitConverter class BitConverter{ constructor(){} GetBy
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
我是 Simple.Data 的新手。但我很难找到如何进行“分组依据”。 我想要的是非常基本的。 表格看起来像: +________+ | cards | +________+ | id |
我现在正在开发一个 JS UDF,它看起来遵循编码。 通常情况下,由于循环计数为 2,Alert Msg 会出现两次。我想要的是即使循环计数为 3,Alert Msg 也只会出现一次。任何想法都
我是一名优秀的程序员,十分优秀!