Run a Java game inside an SWF? - java

So, I wish to program a game in Java, but be able to post it on online video gaming websites. For some reason, most game websites do not support the use of .jar files, so I sadly cannot just publish that. However, I have seen one method that works, but I need an explanation to what it is, and how to do it. Some Java games appear to be put on an independent website, then an SWF loads the page, like a browser. For example, Runescape on Kongregate seems to run like this, despite the actual game being written in Java.
Is this a known method? Does anyone have any idea on how to do this? Please, I'd really like my game written in Java, not ActionScript. I can't imagine running Java from an SWF similar to how a browser does it is that hard. Thanks.

Runescape uses their own version of Java web start to play the game. When you first play Runescape, Jagex uses Java web start to load Java code to your computer that loads the rest of the game. That's what the update check does every time you play.
You can write your Java application so that it uses Java web start. You have to provide a URL on a web page so that the user's browser can download your code to their computer.
Your other choice is to write a Java applet. An applet is run from a web page. The web page has applet HTML to start the applet.

Related

I have made a JFrame which I want to put in an HTML script. (I was going to use a JApplet but it has been deprecated)

I'm using IntelliJ IDEA, I have coded a frame which I want to put into an HTML file so I can run it in my browser, how do I do this now that I cannot use JApplet? I have found this documentation: http://docs.oracle.com/javase/tutorial/deployment/webstart/deploying.html and this http://docs.oracle.com/javase/tutorial/deployment/webstart/deploying.html but I am new to programming and find this difficult to follow. I don't know for instance how I would go about putting my class files and the image that I used in a separate directory nor do I know how I go about signing my application so that it will run in a browser.
I want to put into an HTML file so I can run it in my browser,
You can use the Desktop class. This class allows you to access default applications from your desktop.
Read the section from the Swing tutorial o How to Integrate With the Desktop class for more information and working examples.
See Java Plugin support deprecated and Moving to a Plugin-Free Web.
Note that is one of my 'copy/paste comments' that does not explicitly mention JFrame based apps., however the links are still relevant in that Oracle & browser makers would not be phasing out support for applets if they wanted programmers to keep trying to shove rich client apps (e.g. Swing GUIs) into thin client web pages.
OTOH you can offer a JFrame (or a JApplet) to be launched from a link in a web page to end up free floating on the desktop of the user by using Java Web Start.
Even then, it is not a simple matter for the programmer or the end user. The programmer needs to ensure the app is digitally signed using a code signing certificate issued by a CA (usually they are expensive). The end user used to just be able to click the link, 'OK' the prompts produced by the Java virtual machine, and see the app appear on-screen. But now most browsers will download the launch file to the local file system rather than directly hand it to the JVM to be launched. So the user faces an extra step in explicitly finding the downloaded launch file and double clicking it.
This is all due to security concerns related to bugs in the plug-ins that run things in web pages. So if you were to find a way around all these hoops, please let us know. It is a security bug that requires urgent fixing.

Java Web Application AWT or Swing?

When developing a Java web-based application, is it necessary to use AWT?
I've been researching this question and the answers are confusing. Take for example, Runescape. The user visits the website and can play the game right there. They can also download a desktop application to play the game with.
If I am developing a game application, and my main window is created in a JFrame but all of my graphics are processed in a JPanel inside the main window, will I be able to implement this inside of a web page without much difficulty in the future? I want my game to be accessible simply by visiting the website and running the application.
Additionally, I've seen people reference "Java Web Start". Will this load the java application inside of the website, or does it install/run Java and execute the program (so if my main function opens a JFrame, it would appear on your taskbar). Perhaps I'm having some confusion between a Java application and a Java applet.
..will I be able to implement this inside of a web page without much difficulty in the future?
No. The security environment around applets was made much stronger in recent times, but even then, browsers tend to put further hurdles between applets and 'onscreen, loaded applets'. Chrome is set to remove the plug-in which would normally embed applets and a few other things.
I want my game to be accessible simply by visiting the website and running the application.
Additionally, I've seen people reference "Java Web Start". ..
Yes, offering a link to a JWS launched JFrame will be a lot easier, and a better experience for the end user.

What is the best way to turn this Java Swing application into a sandboxed embed-able (applet or Web Start)?

I am working on a primitive online game client that I wrote as a Java Swing application. My problem is that potential users refuse to download and run any unfamiliar executable. I want my game to be reach as many people as possible and users fear that the executable might contain a virus. That is why I would like to embed the game client into my web page instead. How would you turn this Java executable code (liked below) into an applet?
Thus far I have a main which makes the initial connection to the game server...
https://dl.dropboxusercontent.com/u/214507961/Main.java
A Java Swing GUI that I made with the Netbeans GUI builder...
https://dl.dropboxusercontent.com/u/214507961/GUI.form
Object input/output streams connected to my game/web server...
https://dl.dropboxusercontent.com/u/214507961/Clients_Input.java
https://dl.dropboxusercontent.com/u/214507961/Clients_Output.java
And some buffered images for graphics...
https://dl.dropboxusercontent.com/u/214507961/Image_Repo.java
Note that in future development, I would like to replace much of the primitive looking 2D Swing GUI with content rendered with the Lightweight Java Game Library or some other higher-level video game graphics specific library to make the game look better.
Given that information, what is the best way to make this Java application into an embed-able (applet)? Describe your method and reasoning in such a way that even a college freshman could follow.
Note: Following the advice below, I have tried using WebStart, but I still get an intimidating warning:
Update:
I am in the process of refactoring my code so that the top level container is a JPanel.
I have tried making "GUI" extend JPanel and changing the "gamewindow" from a JFrame into a JPanel.
Modified Main:
https://dl.dropboxusercontent.com/u/214507961/Panel_Top_Level_Container/Main.java
Modified GUI:
https://dl.dropboxusercontent.com/u/214507961/Panel_Top_Level_Container/GUI.java
Despite the changes, Netbeans will not allow this program to run with Java Web Start.
When I enable WebStart and Build/Clean, Netbeans creates two files:
I then clicked Build/Clean and it generated two files:
master-application.jnlp
https://dl.dropboxusercontent.com/u/214507961/Panel_Top_Level_Container/master-application.jnlp
preview-application.html
https://dl.dropboxusercontent.com/u/214507961/Panel_Top_Level_Container/preview-application.html
but no JAR file.
Still working on it. AI moved the remainder of this question to:
Why can't I get Netbeans with Java Web Start enabled to work on my executable?
At this point I'm so tired of putting up with the security hassles and see little to no way to get around certification warnings without paying. I have decided that it would probably be better to just re-write the entire client in HTML5 and javascript.
The basic concept is to build your app (GUI basicly) without using applet specific technologies (like commmunication with web page via JS etc.) and with JPanel as a top level container insteed of of JFrame (Window would be accceptable too, as JApplet extends Window). If you do so, that you will be able to deploy the same code as standalone application and via JNLP as applet.
The digital signature could not be verified by a trusted source.
This is caused by the app. being 'self signed' by a digital certificate we generate ourselves using the SDK tools. Security was increased recently so that 'self signed' apps. get that scary warning. This has been discussed extensively across SO in recent times.
Try looking at the posts under applet+security for details.
Redo the client using HTML5 and Javascript so that you don't run into any prompts or security warnings.

Do I need to convert my java application to an applet to post it on a webpage?

Is it possible to post a java application on a website without converting it into an applet?
I have worked hard on making a game and I want to share it. My game uses the Light Weight Java Game Library, so it is harder to convert to an applet. It is currently an application and
I would not like to start all over again making it an applet....
If I do need to convert it into an applet, Could I still use most of the code?
You won't require much changes if you deploy it as a Java Web Start.
I'd strongly recommend looking into this table that clearly shows the differences between both Java Applications, Java Applets and Java Web Start Applications.

Looking for some information in getting Java to communicate with a website

I was wondering if one could write a Java application and put it on a website and then have it running so that when a user used your website it could interact with some html/javascript page which would communicate with the Java program.
So basically, the html5 would be used to display the java program but all the logic and everything else would be server side in Java.
I don't want to use a java applet since it requires users getting a security warning and most browsers do not autorun a java application. I just think it would look cleaner and work nicer.
Does anyone know anything about this and could give me a little abstract just to point me in the right direction so I can learn more?
Thanks
It's somewhat difficult to tell from your question but you might find GWT useful. You code everything in Java, and the client-side portion gets compiled into html/javascript which communicates to the server portion with AJAX. http://code.google.com/webtoolkit/
I think you should start by developing a simple Java web app using html, jsp and servlet. Try the Google App Engine for deployment as it is free for hosting.
http://www.servletworld.com/servlet-tutorials/simple-servlet-example.html

Categories

Resources