import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class apnr2 extends Applet {
// Anfang Attribute
private JLabel jLabel1 = new JLabel();
private JLabel jLabel2 = new JLabel();
private JLabel jLabel3 = new JLabel();
private JNumberField jNumberField1 = new JNumberField();
private JNumberField jNumberField2 = new JNumberField();
private JButton jButton1 = new JButton();
private JLabel jLabel4 = new JLabel();
private JLabel jLabel5 = new JLabel();
private JLabel jLabel6 = new JLabel();
// Ende Attribute
public void init() {
Panel cp = new Panel(null);
cp.setBounds(0, 0, 303, 300);
add(cp);
// Anfang Komponenten
jLabel1.setBounds(80, 33, 60, 16);
jLabel1.setText("Gewicht:");
jLabel1.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel1);
jLabel2.setBounds(80, 72, 51, 16);
jLabel2.setText("Größe:");
jLabel2.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel2);
jLabel3.setBounds(96, 208, 36, 16);
jLabel3.setText("BMI:");
jLabel3.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel3);
jNumberField1.setBounds(136, 28, 65, 24); // Feld für Gewicht
jNumberField1.setText("");
cp.add(jNumberField1);
jNumberField2.setBounds(136, 72, 65, 24); //Feld für Größe
jNumberField2.setText("");
cp.add(jNumberField2);
jLabel4.setBounds(208, 32, 74, 16);
jLabel4.setText("Kilogramm");
jLabel4.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel4);
jLabel5.setBounds(208, 72, 44, 16);
jLabel5.setText("Meter");
jLabel5.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel5);
jLabel6.setBounds(136, 208, 13, 16);
jLabel6.setText("");
jLabel6.setFont(new Font("MS Sans Serif", Font.PLAIN, 13));
cp.add(jLabel6);
jButton1.setBounds(96, 128, 113, 41);
jButton1.setText("BERECHNEN");
jButton1.setMargin(new Insets(2, 2, 2, 2));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1_ActionPerformed(evt);
}
});
cp.add(jButton1);
// Ende Komponenten
}
// Anfang Methoden
public void jButton1_ActionPerformed(ActionEvent evt) {
double gewicht=0, groesse=0, bmi=0;
gewicht=Integer.parseInt(jNumberField1.getText());
groesse=Integer.parseInt(jNumberField2.getText());
bmi=gewicht/groesse;
bmi=bmi/groesse;
jLabel6.setText(String.valueOf(bmi));
}
// Ende Methoden
}