JApplet在HTML页面中运行失败

发布于 2024-11-25 03:06:29 字数 1496 浏览 1 评论 0 原文

我使用Netbeans中的JUNG库创建了一个JApplet,可以正常编译和运行。但是,当我尝试创建运行该小程序的 html 文件时,仅出现一个灰色窗格,但缺少组件。 我的类是:

   public class View extends JApplet {

   //Here I declare the buttons etc..

   public View()
{
    initializeComponent();
            fetchGraphs();

}


   public static void main(String[] args) throws IOException{

    f = new JFrame();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    x = screenSize.width;
    y = screenSize.height;


    f.getContentPane().add(new View());
    f.setTitle("Social Network Privacy Settings and Access Control");
    f.setLocation(new Point(15, 20));
    f.setSize(new Dimension(x-20,y-50));
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.setResizable(false);

    f.setVisible(true);
}  
}

initializeComponent() 方法将所有组件添加到主窗口。我使用 JFrameBuilder 构建了一些基本组件。 JFrameBuilder 使用方法 addComponent(container, component, x, y, width, height) 来添加组件,

我使用下面的代码:

  contentPane = (JPanel)this.getContentPane();

  //to create the japplet contentpane

  addComponent(contentPane, genGraphButton, (int)(0.35*x),(int)(0.63*y),       
  (int)(0.2*x),28);

  // to add components

然后我创建一个 html 文件:

    <applet code = 'MyPackage.View' 
    archive = 'MyProject.jar',
    width = 1600, 
    height = 800/>

在 /dist 文件夹中,但当我尝试使用 Mozilla Firefox 打开它。奇怪的是,我创建了另一个简单的小程序,这次使用netbeans JBuilder,它在网页中正常运行。

我真的需要一些帮助!

I have created a JApplet using the JUNG library in Netbeans that compiles and runs normally. However, when I try to create an html file that runs the applet, only a grey pane appears but the components are missing.
My class is :

   public class View extends JApplet {

   //Here I declare the buttons etc..

   public View()
{
    initializeComponent();
            fetchGraphs();

}


   public static void main(String[] args) throws IOException{

    f = new JFrame();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    x = screenSize.width;
    y = screenSize.height;


    f.getContentPane().add(new View());
    f.setTitle("Social Network Privacy Settings and Access Control");
    f.setLocation(new Point(15, 20));
    f.setSize(new Dimension(x-20,y-50));
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.setResizable(false);

    f.setVisible(true);
}  
}

The method initializeComponent() adds all the components to the main window. I used JFrameBuilder to build some basic components. JFrameBuilder uses a method addComponent(container, component, x, y, width, height) to add components

I use the code below for that:

  contentPane = (JPanel)this.getContentPane();

  //to create the japplet contentpane

  addComponent(contentPane, genGraphButton, (int)(0.35*x),(int)(0.63*y),       
  (int)(0.2*x),28);

  // to add components

Then I create an html file:

    <applet code = 'MyPackage.View' 
    archive = 'MyProject.jar',
    width = 1600, 
    height = 800/>

in the /dist folder but then only a grey pane appears when I try to open it with Mozilla Firefox. The strange thing is that I have created another simple applet, this time with netbeans JBuilder and it runs normally in a web page.

I really need some help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暮年慕年 2024-12-02 03:06:29

你提到JUNG库,它依赖于两个第三方库,Collections-Generic & Cern Colt 科学图书馆 1.2.0。正如 @othman 所提到的,它们需要添加到小程序的运行时类路径中(添加到 applet 元素的 archive 属性中)。

但我们要清楚的是,请确保 HTML 不仅仅包含 applet 元素。类似这样:

<html>
<body>
<applet 
    code='MyPackage.View' 
    archive='MyProject.jar,jung.jar,collections.jar,colt-scientific.jar'
    alt='Java is DISABLED in this browser!'
    width='1600'
    height='800'>
This browser does not recognize the applet element! 
</applet>
</body>
</html>

当然,您需要将最后 3 个罐子的名称更改为其真实姓名。

You mention the JUNG library, it relies on the two third party libraries, Collections-Generic & Cern Colt Scientific Library 1.2.0. As mentioned by @othman they need to be added to the run-time class-path of the applet (added to the archive attribute of the applet element).

But just so we are clear, make sure the HTML contains more than just the applet element. Something like this:

<html>
<body>
<applet 
    code='MyPackage.View' 
    archive='MyProject.jar,jung.jar,collections.jar,colt-scientific.jar'
    alt='Java is DISABLED in this browser!'
    width='1600'
    height='800'>
This browser does not recognize the applet element! 
</applet>
</body>
</html>

Of course, you'll need to change the names of the last 3 Jars to their real names.

心是晴朗的。 2024-12-02 03:06:29

我不是 Applet 专家,因为我不使用它们,但是 IIRC 您需要 init() 方法来初始化您的视图。小程序不会调用 main(...)

I'm no Applet expert, since I don't use them, but IIRC you need the init() method to initialize your view. main(...) is not called for an applet.

奶气 2024-12-02 03:06:29

首先,我不确定您添加到 html 中的新行是否合法。我的意思是编写 /> 而不需要任何新行和空格。

其次,测试你的 jar 是否真的可用。为此,请转到与您检索不带 HTML 但带有 jar 的 HTML 相同的 URL,即,

如果您的 HTML URL 是: http ://somehost/my.html 在浏览器中输入 http://somehost/MyProject.jar 并看到你可以下载 jar 了。

如果有效,请检查 code 属性。你的包名真的是MyPackage吗?大写?你知道这不符合命名约定吗?

还要检查 java 控制台。在浏览器菜单中的某个位置找到它:这取决于浏览器。我相信您会以异常堆栈跟踪的形式看到原因。

First, I am not sure that new lines you added into the html are legal. I mean write <applet and /> without any new lines and spaces.

Second, test that your jar is really available. To do this go to the same URL that you go to retrieve your HTML without HTML but with jar, i.e.

if your HTML URL is: http://somehost/my.html type in browser http://somehost/MyProject.jar and see that you can download the jar.

if this works check the code attribute. Is your package name really MyPackage? Capitalized? Do you know it is not according the naming convention?

Also check java console. Find it somewhere in menus of your browser: it depends in browser. I believe that you will see the reason there in form of exception stack trace.

乞讨 2024-12-02 03:06:29

您还需要在小程序标签中引用 JUG jar:

<

applet code = 'MyPackage.View' 

archive = 'MyProject.jar , jung_xx.jar',

width = 1600, 

height = 800 /
>

在 archive 属性中添加当前在 netbeans 项目类路径中的所有 jung jar。

you need to reference also the JUG jars in your applet tag :

<

applet code = 'MyPackage.View' 

archive = 'MyProject.jar , jung_xx.jar',

width = 1600, 

height = 800 /
>

in the archive attribute add all jung jars that you have currently in your netbeans project classpath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文