applet
nogen der har nogen ide om hvorfor denne kode virker når jeg kører den i kawa men ikke i I.E browseren?Koden er:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.text.NumberFormat;
public class Bmi extends JApplet
{
public void init()
{
// construct components
Color myColor = new Color(86,107,134);
inputArea1 = new JTextArea(5,5);
inputArea2 = new JTextArea(5,5);
resultField = new JTextField(10);
resultField.setEditable(false);
Dimension size = new Dimension(80,20);
calcButton = new JButton(\"Beregn\");
calcButton.setPreferredSize(size);
calcButton.addActionListener(new ButtonListener());
BevelBorder edge = new BevelBorder(BevelBorder.RAISED);
calcButton.setBorder(edge);
JPanel inputPanel = new JPanel();
inputPanel.setLayout(new GridLayout(3,1,5,5));
inputPanel.add(inputArea1);
inputPanel.add(inputArea2);
inputPanel.add(calcButton);
inputPanel.setBackground(myColor);
inputPanel.setBorder
(new TitledBorder(new EtchedBorder(), \"Beregn din BMI\"));
JPanel outputPanel = new JPanel();
outputPanel.add(resultField);
outputPanel.setBackground(myColor);
outputPanel.setBorder
(new TitledBorder(new EtchedBorder(), \"Din BMI er:\"));
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(3,1));
centerPanel.setBackground(myColor);
centerPanel.add(inputPanel);
centerPanel.add(outputPanel);
Container contentPane = getContentPane();
contentPane.setLayout( new BorderLayout() );
contentPane.add(centerPanel, \"Center\");
}
private JTextArea inputArea1;
private JTextArea inputArea2;
private JTextField resultField;
private JButton calcButton;
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMaximumFractionDigits(0);
formatter.setMinimumFractionDigits(0);
String hoejdeString = inputArea1.getText();
hoejdeString = hoejdeString.replace(\',\', \'.\');
double hoejde = Double.parseDouble(hoejdeString);
String vaegtString = inputArea2.getText();
vaegtString = vaegtString.replace(\',\', \'.\');
double vaegt = Double.parseDouble(vaegtString);
double bmi= vaegt/(hoejde*hoejde);
String result = \"\" + formatter.format(bmi);
resultField.setText(result);
}
}
}