Java Applet 代码可以在浏览器中运行,但不能在 AppletViewer 中运行

标签 java applet viewer appletviewer

当我在浏览器中使用此小程序时,它工作正常,但为什么它不能在小程序查看器中工作?

我尝试使用 jGRASP 和 Eclipse 来查看小程序,但无论我做什么,我都会得到这个:

java.lang.NumberFormatException: null on this line of code

int paramCount = Integer.parseInt( getParameter( "count" ) );

我不明白为什么要这样做。

//file: AppletParameters.java

import javax.swing.JApplet;
import javax.swing.JApplet;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.GridLayout;

public class AppletParameters extends JApplet
{
    private JPanel panel; // panel to display pictures

    public void init( )
    {
        // get the parameter count from the html 'count' parameter
        int paramCount = Integer.parseInt( getParameter( "count" ) );
        // create an array
        ImageIcon [] image = new ImageIcon[paramCount];
        // get each file name from the html 'file' parameter and put into array
        for ( int k=0; k<paramCount; k++ )
            image[k] = new ImageIcon( getImage( getDocumentBase( ), getParameter( "file"+k ) ) );
        // build a new JPanel with GridLayout
        panel = new JPanel( new GridLayout( 2, 5 ) );
        // add images to the panel
        for ( int k=0; k<paramCount; k++ )
            panel.add( new JLabel( image[k] ) );
        // add panel to me (this applet object)
        add( panel );
    }  // end init method
}  // end class

最佳答案

您是否通过AppletViewer向applet传递参数?我怀疑你是。

在 Eclipse 中,您可以通过“运行”菜单“运行配置...”子菜单项,然后“参数”选项卡来执行此操作。

enter image description here

关于Java Applet 代码可以在浏览器中运行,但不能在 AppletViewer 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12658428/

相关文章:

java - 单击按钮更改 jpanel 的背景和字体颜色

ios - 适用于 iOS 的文件查看器

java - 多请求响应转发

java - 在模板类中使用 <limits.h>> 中的最大值

java - 如何防止注册 Activity 重复录入

java - 访问远程服务器/其他网站时,如何在Processing/Java中使用loadStrings?

java - 从 oracle 中插入和提取每小时一分钟

java - 已签名的 Java Applet 在连接到 Web 服务时抛出安全异常

Rstudio 笔记本查看器不显示代码

android - 构建 3D 模型查看器 android?