简体   繁体   English

在浏览器中将 Java 应用程序显示为 Webdemo

[英]Show Java Application as Webdemo in Browser

I have a finished, working java project using swing and awt.我有一个完成的工作 java 项目使用 swing 和 awt。 It works as executable jar, but I want to upload it on a webserver to be a working live demo.它作为可执行文件 jar 工作,但我想将它上传到网络服务器上以作为一个工作现场演示。 This is the main class, there are many other classes used.这个主要是class,还有很多其他类用到。 I found out about java.applet.Applet, but how can I implement it the best way?我发现了 java.applet.Applet,但我怎样才能以最好的方式实现它?

import javax.swing.*;
import java.awt.*;

public class TicTacToe extends JFrame implements Components
{
    

    public TicTacToe()
    {
        super("TicTacToe V1");
        add(statusbar, BorderLayout.NORTH);
        add(playground, BorderLayout.CENTER);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(800,600);
        setResizable(false);
        setVisible(true);

    }

    public static void main(String[] args){
        TicTacToe tictactoe = new TicTacToe();

    }

}

You might consider using CheerpJ: https://github.com/leaningtech/cheerpj-meta您可以考虑使用 CheerpJ: https://github.com/leaningtech/cheerpj-meta

CheerpJ allows to run unmodified Java applications (and even legacy applets) in the browser without any binary plugins. CheerpJ 允许在浏览器中运行未经修改的 Java 应用程序(甚至遗留小程序),无需任何二进制插件。 It is free for non-commercial applications.它对非商业应用是免费的。

Full disclosure: I am lead developer of CheerpJ, and CTO of the company that maintains the project.全面披露:我是 CheerpJ 的首席开发人员,也是维护该项目的公司的首席技术官。

Applets don't work anymore.小程序不再工作了。 There is no standard technology in modern versions of Java that allows you to do this so it works in all browsers. Java 的现代版本中没有标准技术允许您执行此操作,因此它适用于所有浏览器。

Best bet is to create a zip file that users can download, unpack and run.最好的办法是创建一个用户可以下载、解压和运行的 zip 文件。

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

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