5 import java
.awt
.Toolkit
;
6 import java
.awt
.datatransfer
.Clipboard
;
7 import java
.awt
.datatransfer
.ClipboardOwner
;
8 import java
.awt
.datatransfer
.StringSelection
;
9 import java
.awt
.event
.ActionEvent
;
10 import java
.awt
.event
.ActionListener
;
11 import java
.math
.BigDecimal
;
12 import java
.text
.DecimalFormat
;
13 import java
.util
.Vector
;
15 import javax
.swing
.JButton
;
16 import javax
.swing
.JComboBox
;
17 import javax
.swing
.JLabel
;
18 import javax
.swing
.JPanel
;
19 import javax
.swing
.JScrollPane
;
20 import javax
.swing
.JTextArea
;
21 import javax
.swing
.JTextField
;
22 import javax
.swing
.SwingConstants
;
23 import javax
.swing
.event
.ListSelectionEvent
;
24 import javax
.swing
.event
.ListSelectionListener
;
25 import javax
.swing
.table
.TableModel
;
27 import org
.jdesktop
.swingx
.JXPanel
;
29 import Tools
.JCompTools
;
30 import Tools
.JRtaTextField
;
32 import com
.jgoodies
.forms
.builder
.PanelBuilder
;
33 import com
.jgoodies
.forms
.layout
.CellConstraints
;
34 import com
.jgoodies
.forms
.layout
.FormLayout
;
38 public class BMIoberflaeche
extends JXPanel
implements ListSelectionListener
, ActionListener
{
49 JLabel teil2
[] = {null,null,null,null,null,null,null,null,null,null,null,null};
53 public BMIoberflaeche(){
60 FormLayout layob1
= new FormLayout("30dlu,p,10dlu,60dlu,fill:0:grow,30dlu",
62 "10dlu,p,5dlu,p,5dlu,p,5dlu,p,5dlu,p,2dlu,p,20dlu,p,20dlu,p,10dlu");
63 CellConstraints c1
= new CellConstraints();
66 JLabel lblkg
= new JLabel("Körpergewicht in kg");
67 add(lblkg
, c1
.xy(2,2));
68 masse
= new JRtaTextField("FL", true,"6.2","RECHTS");
69 masse
.setText("0,00");
70 add(masse
,c1
.xy(4,2));
71 JLabel lblcm
= new JLabel("KörpergröÃe in cm");
72 add(lblcm
, c1
.xy(2,4));
73 cm
= new JRtaTextField("ZAHLEN",true);
74 cm
.setHorizontalAlignment(SwingConstants
.RIGHT
);
78 bnr1
= new JButton("rechnen...");
79 bnr1
.setActionCommand("rechnen");
80 bnr1
.addActionListener(this);
83 JLabel lblbmi
= new JLabel("individueller BMI:");
84 add(lblbmi
, c1
.xy(2,8));
86 bmi
.setForeground(Color
.BLUE
);
90 JLabel lblsort1
= new JLabel("individuelle");
91 add(lblsort1
, c1
.xy(2,10));
92 JLabel lblsort2
= new JLabel("Eingruppierung:");
93 add(lblsort2
, c1
.xy(2,12));
94 gruppe
= new JLabel("");
95 gruppe
.setForeground(Color
.RED
);
96 add(gruppe
,c1
.xy(4,12));
98 add(getTeil2(),c1
.xyw(2,14,4, CellConstraints
.FILL
,CellConstraints
.FILL
));
100 bnr1
= new JButton("Schliessen");
101 bnr1
.setActionCommand("schliessen");
102 bnr1
.addActionListener(this);
103 add(bnr1
,c1
.xy(4,16));
106 private JPanel
getTeil2(){
107 FormLayout teil2Pan
= new FormLayout("0dlu,p,10dlu,60dlu,0dlu",
108 "p,10dlu,p,5dlu,p,5dlu,p,5dlu,p,5dlu,p,10dlu");
109 PanelBuilder t2area
= new PanelBuilder(teil2Pan
);
110 t2area
.getPanel().setOpaque(false);
111 CellConstraints ct2
= new CellConstraints();
113 teil2
[0] = new JLabel("Gewichtsklassifiktation nach WHO");
114 t2area
.add(teil2
[0], ct2
.xyw(2,1,4));
116 teil2
[1] = new JLabel("Normalgewicht");
117 t2area
.add(teil2
[1], ct2
.xy(2,3));
118 teil2
[2] = new JLabel("Ãbergewicht");
119 t2area
.add(teil2
[2], ct2
.xy(2,5));
120 teil2
[3] = new JLabel("Adipositas Grad 1");
121 t2area
.add(teil2
[3], ct2
.xy(2,7));
122 teil2
[4] = new JLabel("Adipositas Grad 2");
123 t2area
.add(teil2
[4], ct2
.xy(2,9));
124 teil2
[5] = new JLabel("Adipositas Grad 3");
125 t2area
.add(teil2
[5], ct2
.xy(2,11));
127 teil2
[6] = new JLabel("18,5 - 24,9");
128 t2area
.add(teil2
[6], ct2
.xy(4,3));
129 teil2
[7] = new JLabel("25,0 - 29,9");
130 t2area
.add(teil2
[7], ct2
.xy(4,5));
131 teil2
[8] = new JLabel("30,0 - 34,9");
132 t2area
.add(teil2
[8], ct2
.xy(4,7));
133 teil2
[9] = new JLabel("35,0 - 39,9");
134 t2area
.add(teil2
[9], ct2
.xy(4,9));
135 teil2
[10] = new JLabel("40,0 - mehr");
136 t2area
.add(teil2
[10], ct2
.xy(4,11));
146 t2area
.getPanel().validate();
147 return t2area
.getPanel();
151 public void valueChanged(ListSelectionEvent arg0
) {
152 // TODO Auto-generated method stub
155 private void doRechnen(){
156 DecimalFormat dcf
= new DecimalFormat("#####0.00");
157 BigDecimal gross
= new BigDecimal(Double
.parseDouble(cm
.getText().trim())/100);
159 //System.out.println(gross);
160 BigDecimal gewicht
= new BigDecimal(Double
.parseDouble(masse
.getText().trim().replace(",", ".")));
161 //System.out.println(gewicht);
162 BigDecimal dbmi
= gewicht
.divide(gross
, BigDecimal
.ROUND_HALF_UP
);
163 bmi
.setText(dcf
.format(dbmi
));
164 Double ddbmi
= dbmi
.doubleValue();
165 Double
[][] dvergleich
= {{0.0,18.4},
171 if(ddbmi
< dvergleich
[0][1]){
172 gruppe
.setText("Untergewicht");
173 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
176 if( (ddbmi
>= dvergleich
[1][0]) && (ddbmi
<= dvergleich
[1][1])){
177 gruppe
.setText("Normalgewicht");
178 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
181 if( (ddbmi
>= dvergleich
[2][0]) && (ddbmi
<= dvergleich
[2][1])){
182 gruppe
.setText("Ãbergewicht");
183 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
186 if( (ddbmi
>= dvergleich
[3][0]) && (ddbmi
<= dvergleich
[3][1])){
187 gruppe
.setText("Adipositas Grad 1");
188 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
191 if( (ddbmi
>= dvergleich
[4][0]) && (ddbmi
<= dvergleich
[4][1])){
192 gruppe
.setText("Adipositas Grad 2");
193 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
196 if( (ddbmi
>= dvergleich
[5][0]) ){
197 gruppe
.setText("Adipositas Grad 3");
198 doClipBoard(gruppe
.getText(),dcf
.format(dbmi
));
203 private void doClipBoard(String gruppe
,String bmi
){
204 String toClip
= "Der ermittelte BodyMass-Index (BMI) liegt bei "+bmi
+
205 ". Die Eingruppierung nach WHO ist daher "+gruppe
+".";
206 StringSelection stringSelection
= new StringSelection( toClip
);
207 Clipboard clipboard
= Toolkit
.getDefaultToolkit().getSystemClipboard();
208 clipboard
.setContents( stringSelection
, null );
213 public void actionPerformed(ActionEvent arg0
) {
214 String cmd
= arg0
.getActionCommand();
216 if(cmd
.equals("rechnen")){
218 //masse/(cm*cm) = bmi
221 if(cmd
.equals("schliessen")){