Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default 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).

    Please help!

    Thanks for taking your time and clicking on this thread,

    Alerhau

  2. #2
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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.

  3. #3
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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?

  4. #4
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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.

  5. #5
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    How is these simple steps that you were talking about at the step 1?

  6. #6
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    have you ever made a JApplet before?

  7. #7
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Nope I have'nt.

  8. #8
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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

  9. #9
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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.)

  10. #10
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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.

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    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.
    db

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    Quote Originally Posted by kammce View Post
    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.
    This defeats the purpose of a forum, which is to share problems and their possible solutions.

    Also, spoonfeeding denies the poster the chance to learn.

    db

  13. #13
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    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.

  14. #14
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    sorry, double post.

  15. #15
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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.

  16. #16
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    Check out DarrylBurke's post about 4 post above yours.

  17. #17
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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)

  18. #18
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Oh, I have a bad connection. Means that I get a lot of double posts.

  19. #19
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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.

    Alex Haus

  20. #20
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default

    What errors are you getting? Are they compiler or runtime errors or is the Applet not starting up?

Page 1 of 2 12 LastLast

Similar Threads

  1. Problem of conversion JFrame to Applet
    By Rekuta in forum Java Applets
    Replies: 9
    Last Post: 05-16-2010, 04:31 AM
  2. Jframe pass variable to Applet
    By wayn in forum AWT / Swing
    Replies: 0
    Last Post: 03-10-2010, 10:54 AM
  3. Embed java applet in JFrame
    By Bill89 in forum New To Java
    Replies: 0
    Last Post: 12-09-2009, 02:05 PM
  4. Closing Popup JFrame in Applet
    By Arsenic in forum Java Applets
    Replies: 3
    Last Post: 04-10-2009, 09:37 PM
  5. JFrame vs Applet
    By baltimore in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 04:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •