资源描述:
《BMI体重测定代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、rtjavax.swing.*;importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;importjava.awt.Container;importjava.awt.GridBagLayout;importjava.awt.GridBagConstraints;importjava.awt.Font;publicclassBMICaculatorimplementsActionListener{privatestatic
2、finalintWINDOW_WIDTH=350;privatestaticfinalintWINDOW_HEIGHT=220;privatestaticfinalintFIELD_WIDTH=22;privatestaticfinalStringJFranme=null;privateJFramewindow;JLabelprescriptionLabel;JLabelweightLabel;JLabelheightLabel;JLabelresultLabel;privateJLabelevalua
3、teLabel;privateJTextFieldweightField,heightField,resultField,evaluateField;privateJButtonrun,rest;publicBMICaculator(){initComponent();}privatevoidinitComponent(){window=newJFrame("BMICaculator");window.setSize(WINDOW_WIDTH,WINDOW_HEIGHT);window.setFont(
4、newFont("Simsun",Font.PLAIN,14));Containerc=window.getContentPane();c.setLayout(newGridBagLayout());GridBagConstraintsgc=newGridBagConstraints();prescriptionLabel=newJLabel("请输入你的体重和身高,可以计算你的BMI值。");prescriptionLabel.setFont(newFont("Simsun",Font.PLAIN,1
5、4));gc.gridx=0;gc.gridy=0;gc.gridwidth=2;c.add(prescriptionLabel,gc);weightLabel=newJLabel("体重(公斤)");weightLabel.setFont(newFont("Simsun",Font.PLAIN,14));weightField=newJTextField(FIELD_WIDTH);gc.gridx=0;gc.gridy=1;gc.gridwidth=1;c.add(weightLabel,gc);gc
6、.gridx=1;gc.gridy=1;c.add(weightField,gc);heightLabel=newJLabel("身高(米)");heightLabel.setFont(newFont("Simsun",Font.PLAIN,14));heightField=newJTextField(FIELD_WIDTH);gc.gridx=0;gc.gridy=2;c.add(heightLabel,gc);gc.gridx=1;gc.gridy=2;c.add(heightField,gc);r
7、esultLabel=newJLabel("BMI计算结果");resultLabel.setFont(newFont("Simsun",Font.PLAIN,14));resultField=newJTextField(FIELD_WIDTH);gc.gridx=0;gc.gridy=3;c.add(resultLabel,gc);gc.gridx=1;gc.gridy=3;c.add(resultField,gc);evaluateLabel=newJLabel("评价");evaluateLabe
8、l.setFont(newFont("Simsun",Font.PLAIN,14));evaluateField=newJTextField(FIELD_WIDTH);gc.gridx=0;gc.gridy=4;c.add(evaluateLabel,gc);gc.gridx=1;gc.gridy=4;c.add(evaluateField,gc);