Results 1 to 20 of 28
Thread: JFrame to Applet?
- 08-12-2011, 09:47 PM #1
JFrame to Applet?
Is it possible to easy transform a JFrame into an applet without drawing any graphics at all? I really need this for my website. My game Loaie will soon be released & it would be good if I could create it into an Applet.
On the JFrame I have a lot of images, JLabels, JPanels. (A lot of "J" (Like JLabel) stuff).
Thanks for taking your time and clicking on this thread,
- 08-12-2011, 10:13 PM #2
Alright, there are a few ways of going about deploying your game to the web.
1) You could go though your application and change some things around to make it into an Applet. It does not take too long but It will take some time based on the size of your program.
2) Your next option would be to use Java Web Start also known as JNLP to deploy your game.
3) If all else fails you could have the people download it and run in on their computers.
If you need help with any of these, just ask.
- 08-12-2011, 10:36 PM #3
Does the JNLP works for using it as an Applet? Don't you have to download it when you run it on the web then?
- 08-12-2011, 10:45 PM #4
All the user has to do is download a simple (and very small) XML like file that will use java webstart to download the game from your server to their computer. Once that is done, it will act as if the game was downloaded onto their computer. Once the game is over, the .JNLP file will remain, but all reminents of the game that was downloaded to the user's computer will be deleted afterward. If they ever want to play the game, they can double click on the JNLP file and the game should be reloaded again and they get to play. They do not have to download the game in this fashion. The JNLP method is meant for applications before they become Applets. This will allow you to skip converting your program into a applet. If you really need it to be an applet I will tell you how I usually go about converting my games to Applets, but otherwise, use JNLP.
- 08-12-2011, 10:59 PM #5
How is these simple steps that you were talking about at the step 1?
- 08-12-2011, 11:13 PM #6
have you ever made a JApplet before?
- 08-13-2011, 05:47 PM #7
Nope I have'nt.
- 08-13-2011, 05:59 PM #8
Alright! First things first, take a look at:
How to Make Applets (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
Applet (Java 2 Platform SE v1.4.2)
Also, give me some of your source code so I can tell you what you need to change.
All of my code is made so that it can be easily turned into Applet. Not only that but if you have a full flegded game, you could just have the applet be the source that downloads/starts the game for you then a new JFrame pops up from that applet and they play from that JFrame. Just coming up with some ways to make things easier on you.
But if anything, Applets start with `extends JApplet` not `extends JFrame,` but that is pretty obvious. Applets do not start with `public static void main(String cheese)` They start with `public void init()` There are other classes that go along with public void init() like `public void destroy` for when it finishes up and the browsers wants nothing less but for your applet to be killed. The main difference is how things are handeling but most of swing and awt work in JApplet
- 08-13-2011, 06:09 PM #9
If you could change it for me, I would be more than happy. You will also be on the top of the credits. (This is too hard for me, not knowing anything and make 600 rows of code into a JApplet.)
- 08-13-2011, 06:15 PM #10
Lol, 600 lines of code is nothing! (No offense) Because this is such a simple procedure, I will do this favor for you. Send me the link via a Private Message. When I make the changes, you must look at the changes I have made so that you can do this in the future.
Lastly, how many different classes do you have? And how many JFrames do you have popping up. If only one then just send over the file and I will convert it.
- 08-13-2011, 06:20 PM #11
This is a forum, not a code factory. You have been given enough information to do this yourself. All you have to do is try -- and you know that you can post any specific problem for further help, if needed.
Just to summarize the main steps:
Extend JApplet instead of JFrame
Move any code in the JFrame's constructor to the JApplet's init() method. Remove any setting for defaultCloseOperation if present.
Remove any call to System.exit(...). It's not allowed in an Applet.
Stop any running Threads and release any native resources in destroy().
The better approach is to base any application on a JPanel. This assembled JPanel, with all its children and code, can be set as the contentPane of either a JFrame, for a desktop application, or a JApplet, for running in a browser. That's probably what kammce implied by
All of my code is made so that it can be easily turned into Applet.
- 08-13-2011, 06:22 PM #12
- 08-13-2011, 06:28 PM #13
Sorry about that DarrylBurke. I did not I was doing something wrong when I accepted this user's offer to modify their code for them, and thank you for explaining the process a bit clearer than I would have.
@Alerhau: well there you have it. Curtsy of DarrylBurke.
- 08-13-2011, 06:29 PM #14
sorry, double post.
- 08-13-2011, 06:30 PM #15
I only have one. Give me your emailadress via the Private Message & I'll mail a folder with images & a .java file in. (In my opinion it's easyer to only have one class, that makes it easyer for me to know where everything is.
- 08-13-2011, 06:34 PM #16
Check out DarrylBurke's post about 4 post above yours.
- 08-13-2011, 06:37 PM #17
If you could give me your e-mail I will send you over the .Java file with images. Now I trust you that you don't steal the game. (It's ofcorse copyrighted)
- 08-13-2011, 06:39 PM #18
Oh, I have a bad connection. Means that I get a lot of double posts.
- 08-13-2011, 06:46 PM #19
I tried, I did my best. And I can't solve this. If I get help this time my game will be able to run on the web. Else, I give up.
- 08-13-2011, 06:53 PM #20
- By Rekuta in forum Java AppletsReplies: 9Last Post: 05-16-2010, 03:31 AM
- By wayn in forum AWT / SwingReplies: 0Last Post: 03-10-2010, 09:54 AM
- By Bill89 in forum New To JavaReplies: 0Last Post: 12-09-2009, 01:05 PM
- By Arsenic in forum Java AppletsReplies: 3Last Post: 04-10-2009, 08:37 PM
- By baltimore in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 03:24 AM