0

I have a finished, working java project using swing and awt. It works as executable jar, but I want to upload it on a webserver to be a working live demo. This is the main class, there are many other classes used. I found out about java.applet.Applet, but how can I implement it the best way?

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();

    }

}

2 Answers2

2

You might consider using 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. It is free for non-commercial applications.

Full disclosure: I am lead developer of CheerpJ, and CTO of the company that maintains the project.

alexp
  • 811
  • 4
  • 10
  • 1
    Website is not clear. What exactly can the community edition be used for? – Thorbjørn Ravn Andersen Mar 01 '22 at 17:50
  • Thanks for recommending. I converted the jar file using cheerpj into a js file and created and uploaded the html file to a webserver. But cheerpj keeps inizializing / run time ready not loading the app. The network tab shows the error "An unexpected error occurred while trying to open file /app/myapp.jar". Do you know how to fix? – jaqueslemans Mar 01 '22 at 21:26
  • Please see this FAQ entry: https://docs.leaningtech.com/cheerpj/Frequently-Asked-Questions#my-application-compiled-with-cheerpj-does-not-work-and-i-just-see-the-cheerpj-runtime-ready-on-the-top-of-the-screen-whats-going-on Most usually the problem is, as the error suggest, that the JAR is not available over HTTP at the expected location. Please notice that /app refers to the HTTP root and it's not page relative. – alexp Mar 02 '22 at 10:27
1

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.

Best bet is to create a zip file that users can download, unpack and run.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347