简体   繁体   English

嵌入Java Applet

[英]Embedding a Java Applet

I'm trying to get a Java Applet to display on a webpage. 我正在尝试使Java Applet显示在网页上。 The applet runs in Eclipse, but does nothing on the webpage. 该小程序在Eclipse中运行,但在网页上不执行任何操作。 For reference here is the applet (no, it's not complete): 供参考的是小程序(不,它不完整):

package TestProg.webClient;

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

public class UserLogin extends Applet {
    String accountId = "";

    public void init() {
        TextField username = new TextField(10);
        TextField password = new TextField(10);
        Button login = new Button("   Log In   ");
        add(username);
        add(password);
        add(login);
    }
}

And here is the HTML code: 这是HTML代码:

<body>
  <center>
    <div id="title"><h1>UserLogin</h1></div>
  </center>
  <applet code="sp.jar" width="400" height="100" alt="This isn't working"></applet>
</body>

I've also tried embedding with <object> and <embed> , have tried with both Chrome and Firefox on a Linux machine, and for some reason took the .class file out of the .jar and tried that. 我还尝试使用<object><embed> ,并尝试在Linux机器上同时使用Chrome和Firefox,并出于某种原因将.class文件从.jar中取出并进行了尝试。 Absolutely nothing displays on the webpage. 网页上绝对没有任何显示。

Any help would be greatly appreciated. 任何帮助将不胜感激。 Richard 理查德

I discovered what the problem was, and there seems to be a severe lacking of this knowledge out there.... 我发现了问题所在,而且似乎严重缺乏这种知识。

The HTML tag should look like this... HTML标签如下所示:

<applet code=NameOfPackage.NameOfApplet archive=NameOfApplet.jar width=300 height=300>

Thanks to all who helped... 感谢所有帮助...

Can the code attributte be a .jar ? 代码属性可以是.jar吗? Everything in the right directory? 一切都在正确的目录中吗?

Try something like this: 尝试这样的事情:

<applet code=NameOfApplet.class name=NameOfApplet archive=NameOfApplet.jar
    width=300 height=300>
    <param name="bgcolor" value="ffffff">
    <param name="fontcolor" value="000000">
    Your browser is not Java enabled.
</applet>

Try adding a Jpanel before you add your button and text box. 在添加按钮和文本框之前,请尝试添加Jpanel。

JPanel panel = new JPanel();
    Container content = getContentPane();
    content.setLayout(new GridBagLayout()); // Used to center the panel
    content.add(panel);

Have you installed the pluging for java on yout browser ? 您是否在浏览器上安装了Java插件?

http://www.oracle.com/technetwork/java/index-jsp-141438.html http://www.oracle.com/technetwork/java/index-jsp-141438.html

If you don't need it on the site, you could wrap it using http://launch4j.sourceforge.net/ and providing a link to download the executable you made. 如果您在网站上不需要它,则可以使用http://launch4j.sourceforge.net/对其进行包装,并提供一个链接来下载您制作的可执行文件。 Perhaps wrap it as an exe than modify the java code to submit values to the server. 也许将其包装为exe,而不是修改Java代码以将值提交给服务器。 Then, tell the user to reload the page if the server responds that it received the information. 然后,如果服务器响应它接收到该信息,则告诉用户重新加载页面。 Sorry, it is a clumsy workaround- but it might work. 抱歉,这是一个笨拙的解决方法-但它可能会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM