First off, this is for my web design class. I am doing a sort of "promotion website" for the game I made in my Computer Science 2 final for the final in this class. Everything is all good, except that I wanted to add a feature where you could play the game from the browser. The website is all in a local folder, and he will be examining it on his computer, so everything will be local, no servers. How would I go about adding the game to the website?
Asked
Active
Viewed 4.3k times
3
-
1Are you trying to use java or javascript? – Ahsan Dec 07 '16 at 23:37
-
@Raptor The game was programmed in java, my website is in html and css – IsaacLightning Dec 07 '16 at 23:44
1 Answers
3
NOTE: Applets are deprecated in JDK 9
You will need java applets for your java code to run in browser. Here is some intro about applets: http://docs.oracle.com/javase/tutorial/deployment/applet/
Here is a simple example:
Your java code:
import java.applet.*;
import java.awt.*;
public class Main extends Applet{
public void paint(Graphics g){
g.drawString("Welcome in Java Applet.",40,20);
}
}
Compiling the code will generate a .class file. For example: Main.class
Then embed the Main.class file in your browser:
<HTML>
<HEAD>
My game applet
</HEAD>
<BODY>
<div >
<APPLET CODE="Main.class" WIDTH="800" HEIGHT="500"></APPLET>
</div>
</BODY>
</HTML>
Some basic tutorials here: http://www.dreamincode.net/forums/topic/229033-introduction-to-java-applets/
Another way: Java Web Start
Use Java Web Start which allows applications to be launched through browsers or via the Java Network Launching Protocol.
Some valuable resources here: https://stackoverflow.com/tags/java-web-start/info

Ahsan
- 3,845
- 2
- 36
- 36
-
-
1
-
@IsaacLightning yes right. Code modification needed to make it run as applets. – Ahsan Dec 08 '16 at 00:14
-
@AlexSifuentes Yes applets are blocked by browsers however by changing some settings we can allow applets to run: http://stackoverflow.com/questions/16196425/java-error-your-security-settings-have-blocked-a-local-application-from-runnin – Ahsan Dec 08 '16 at 00:17
-
What exactly would I need to change? I can upload the code if you want – IsaacLightning Dec 08 '16 at 00:28
-
The amount of changes needed actually depends on your code. Go ahead and upload the code please! – Ahsan Dec 08 '16 at 00:37
-
Here is the code: http://www.mediafire.com/file/d7wngymv3632pa3/SamuraiGameSRC111715.zip – IsaacLightning Dec 08 '16 at 01:03
-
-
Your application uses Swing. You should use `Java Web Start` instead of applets. Updated my answer. – Ahsan Dec 08 '16 at 01:37
-
-
Ok I tried extending my main class, SamuraiBoardGame, off of Applet. I also have my html like this ` ` Now it gives java.lang.reflect.InvocationTargetException and I don't know how to fix this – IsaacLightning Dec 08 '16 at 16:23
-
4This answer is outdated, Java applets are no longer supported on major browsers. – NoName Oct 27 '20 at 18:54