Applet传递参数抱错

zr_dixuexiongying 2008-03-11 09:41:18
我测试了一下小应用程序传递参数抱错,希望各位打虾指点.

测试的Applet程序:

FontPassDemo.java

import java.awt.*;
import java.applet.Applet;

public class FontPassDemo extends Applet
{
private String quote ;

public void init()
{
quote = "Happiness is an attitude.";
String fontname = getParameter(font);
int fontsize = Integer.parseInt(getParameter("size"));
f = new Font(fontname,Font.ITALIC,fontsize);
}

public void paint(Graphics g)
{
g.setFont(f);
g.drawString(quote,20,100);
}
}

FontPassDemo.html

<html>
<applet code="FontPassDemo.class" width=400 heigth=200>
<parame name=font value="Helvetica">
<param name=size value="28">
</applet>
</html>

包错信息:

java.lang.NumberFormatException:null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.parseInt(Integer.java:497)
at FontPassDemo.init(FontPassDemo.java 13)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
...全文
53 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
EricPan2023 2008-03-11
  • 打赏
  • 举报
回复
应该是参数font的 parm 串成了parme
caiming250 2008-03-11
  • 打赏
  • 举报
回复
还有一个 不紧要的错误 heigth=200

把这个改成:

height=200
caiming250 2008-03-11
  • 打赏
  • 举报
回复
你把 TestApplet 还是改成你的 class名字(FontPassDemo)
caiming250 2008-03-11
  • 打赏
  • 举报
回复
   private String quote ; 
private Font f;
public void init()
{
quote = "Happiness is an attitude.";
String fontname = getParameter("font");
int fontsize = Integer.parseInt(getParameter("size"));
f = new Font(fontname,Font.ITALIC,fontsize);
}

public void paint(Graphics g)
{
g.setFont(f);
g.drawString(quote,20,100);
}



<html> 
<applet code="TestApplet.class" width=400 heigth=200>
<param name=font value="Helvetica"/>
<param name=size value="28"/>
</applet>
</html>



这样 没有问题! 你的代码 到处都是小错误
cydp007 2008-03-11
  • 打赏
  • 举报
回复
NumberFormatException 当应用程序试图将字符串转换成一种数值类型,但该字符串不能转换为适当格式时,抛出该异常。



int fontsize = Integer.parseInt(getParameter("size")); 看你写的这句好像是对的.

不过看JDK
<html>
<applet code="FontPassDemo.class" width=400 heigth=200>
<parame name=font value="Helvetica">
<param name=size value="28">
</applet>
</html>


FontPassDemo.class 那里改成 FontPassDemo 不要后面 ...

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧