gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:02:20 26 4
gpt4 key购买 nike

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

我尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com