Proszę o przerobienie mojego kodu na Applet aby można było wrzucić go na stronę internetową .
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.FlowLayout;
import javax.swing.JButton;
import java.text.DecimalFormat;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//------------------------------------------------------------------------------
public class BMICalculator extends JFrame implements ActionListener {
private JTextField bmiF;
private JButton bmiB;
private DecimalFormat pattern;
private JTextField wagaF;
private JLabel wagaL;
private JTextField wzrostF;
private JLabel wzrostL;
public BMICalculator() {
super("Kalkulator BMI");
this.initVars();
this.setFrame();
}
//--------------------------------------------------------------------------------
private void initVars() {
pattern = new DecimalFormat("#.##");
bmiB = new JButton("Przelicz!");
bmiF = new JTextField("0", 5);
bmiF.setEditable(false);
wzrostL = new JLabel("Wzrost w CM: ");
wzrostF = new JTextField(5);
wagaL = new JLabel("Waga w KG: ");
wagaF = new JTextField(5);
bmiB.addActionListener(this);
}
private void setFrame() {
this.setLayout(new FlowLayout());
this.add(wagaL);
this.add(wagaF);
this.add(wzrostL);
this.add(wzrostF);
this.add(bmiB);
this.add(bmiF);
this.pack();
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
this.setResizable(false);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e) // wyjatek
{
try {
double weight = Double.parseDouble(this.wagaF.getText());
double height = Double.parseDouble(this.wzrostF.getText());
// wzrost centymetrach
height /= 100;
double BMI = weight / (height * height);
String BMIstring = pattern.format(BMI);
this.bmiF.setText(BMIstring);
/*catch an exception*/
} catch (NumberFormatException ex) {
System.out.println("złe dane");
}
}
public static void main(String[] args) {
new BMICalculator();
}
}