傳遞參數添加兩個整數值以下Java程序被編譯成功,但是當我嘗試使用小程序查看運行它,我得到以下(在命令提示符)有消息「小程序未初始化 「在小程序窗口中。通過一個applet
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)
我無法找出問題...
任何幫助,將不勝感激!
該課程必須標記爲公開,例如'公共類ParamDemo擴展Applet'只是'類ParamDemo extends Applet' – gparyani 2013-05-01 17:39:04
它的工作原理...謝謝@gparyani – Salman 2013-05-01 17:52:54