我在编写一个简单的java applete程序:
编写一个实现如下功能的Applet:从它的HTML文件中取出三个参数x,y,op做算术运算,其中:x、y为int型数,op为运算符(=,+,-,×,/之一),并显示x op y的结果。
源文件如下:
package Applet_practise1;
import java.applet.*;
import javax.swing.*;
public class Applet_practise1 extends Applet {
/**
*
*/
private String X;
String Y;
String op;
int x;
int y;
int result;
private static final long serialVersionUID = 1L;
private String NULL;
/**
*
*/
public void start()
{
if("="==op)
equal();
if("+"==op)
addition();
if("-"==op)
subtration();
if("*"==op)
mutipication();
if("/"==op)
divition();
}
public void init(){
// if(getParameter("x1")!=NULL)
X=getParameter("x1");
JOptionPane.showMessageDialog(null, X);
//if(getParameter("y1")!=NULL)
Y=getParameter( "y1");
JOptionPane.showMessageDialog(null, Y);
if(getParameter( "op1")!=NULL)
op=getParameter( "op1");
JOptionPane.showMessageDialog(null, op);
//if(X!=NULL)
x=Integer.parseInt(X);
//if(Y!=NULL)
y=Integer.parseInt(Y);
}
public void equal(){
System.out.println(x+"op"+y);
}
public void addition(){
result=x+y;
System.out.println(x+"op"+y+"="+result);
}
public void subtration(){
result=x-y;
System.out.println(x+"op"+y+"="+result);
}
public void mutipication(){
result=x*y;
System.out.println(x+"op"+y+"="+result);
}
public void divition(){
result=x/y;
//System.out.println(x+"op"+y+"="+result);
JOptionPane.showMessageDialog(null, result+"");
}
}
HTML文件内容如下:
<HTML>
<BODY>
<APPLET CODE="Applet_practise1.class" WIDTH="200" HEIGHT="300">
<PARAM NAME=x1 VALUE="36">
<PARAM NAME=y1 VALUE="12">
<PARAM NAME=op1 VALUE="/">
</APPLET>
</BODY>
</HTML>
可是每次一运行,就出现以下提示:
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Applet_practise1.Applet_practise1.init(Applet_practise1.java:49)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
请问一下该怎么解决?我用的是Eclipse3.2