java源文件如下 Calc.java:
import javax.swing.JApplet;
import javax.swing.JTextArea;
public class Calc extends JApplet {
public void init() {
double first = Double.parseDouble(getParameter("first"));
double second = Double.parseDouble(getParameter("second"));
char operator = getParameter("operator").charAt(0);
double result = 0;
switch(operator) {
case '+': result = first + second; break;
case '-': result = first - second; break;
case '*': result = first * second; break;
case '/': result = first / second; break;
}
JTextArea text = new JTextArea(3,100);
text.setEditable(false);
String a = "************************";
String s = String.format("%.2f %c %.2f = %.2f",first,operator,second,result);
text.append(a+"\n");
text.append(s+"\n");
text.append(a+"\n");
add(text);
}
}
html文件如下 a.html: