以下 java 程序已成功编译,但当我尝试使用appletviewer运行它时,我在 applet 窗口中收到以下消息(在命令提示符下)并显示消息“ applet not initialized ”。
import java.applet.*;
import java.awt.*;
/*
<applet code="ParamDemo" width="300" height="300">
<param name="first" value="20">
<param name="second" value="30">
</applet>
*/
class ParamDemo extends Applet
{
int x,y,sum;
public void init()
{
x=Integer.parseInt(getParameter("first"));
y=Integer.parseInt(getParameter("second"));
}
public void paint(Graphics g)
{
sum=x+y;
g.drawString("Total Sum is"+sum,100,100);
}
}
在命令提示符下 -
C:\Documents and Settings\Salman\Desktop>javac ParamDemo.java
C:\Documents and Settings\Salman\Desktop>appletviewer ParamDemo.java
load: ParamDemo is not public or has no public constructor.
java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access a
member of class ParamDemo with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
at java.lang.Class.newInstance0(Class.java:368)
at java.lang.Class.newInstance(Class.java:327)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:793)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:722)
at sun.applet.AppletPanel.run(AppletPanel.java:379)
at java.lang.Thread.run(Thread.java:722)
我无法弄清楚问题所在...
任何帮助,将不胜感激 !