File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes using an applet to open another window (JFrame) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "using an applet to open another window (JFrame)" Watch "using an applet to open another window (JFrame)" New topic
Author

using an applet to open another window (JFrame)

J R Hatch
Greenhorn

Joined: Sep 07, 2011
Posts: 26
So I created a regular Java application that you compile with javac and run with java at the command line. It opens a little frame where it asks for your name and choice of color, then uses those to open a large frame holding a game board and instantiates a game (you against other humans at the same terminal or AI opponents), hiding the little frame. Works fine.

I tried to turn it into an applet by taking the setup-frame class and superficially editing it to be a setup-applet on a webpage. That part seemed to work. However, when I use it and try to start the game, the new game window is tiny and (when expanded) still only holds one dot. The code for the applet is:



Forgive the sophomoric response to the lack of name.

The code for the frame containing the game is



I hesitate to post the code for the "JuroOneScreenPanel" class, since it's where much of the game running junk is handled, which would be long and unhelpful to anyone helping me.

Thanks in advance.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
It would be a better experience for the end user if the frame(s) were launched using Java Web Start.

And speaking of frames, it is generally only necessary to have one frame in an application. Other free floating UI elements might be shown in a JDialog or JOptionPane, or alternately included in the main UI using a CardLayout or any number of components (e.g. JSplitPane, JTabbedPane, JDesktopPane/JInternalFrame).


Andrew Thompson
http://pscode.org/
J R Hatch
Greenhorn

Joined: Sep 07, 2011
Posts: 26
Andrew Thompson wrote:It would be a better experience for the end user if the frame(s) were launched using Java Web Start.


I don't say you're wrong, but why? As it runs (if I could get it to run), there would be an applet on the page where they type their name and pick a color, then launch a new frame for the game. With web start (jnlp), they would hit a button ("Launch") which would open a small frame to enter the name and pick a color, then launch the game frame. Unless that solves the network inaccessibility, I don't see why that's better.


And speaking of frames, it is generally only necessary to have one frame in an application. Other free floating UI elements might be shown in a JDialog or JOptionPane, or alternately included in the main UI using a CardLayout or any number of components (e.g. JSplitPane, JTabbedPane, JDesktopPane/JInternalFrame).


It's only necessary to have one, but is it that bad to have two? I use the name of the person starting the game in the constructor of the game frame, so I threw in a quick little setup frame/applet before opening the big one containing the game board. I do use dialogs and JOptionPanes for other things within the game.
Andrew Thompson
Ranch Hand

Joined: Aug 05, 2010
Posts: 77
    
    5
J R Hatch wrote:
Andrew Thompson wrote:It would be a better experience for the end user if the frame(s) were launched using Java Web Start.

I don't say you're wrong, but why? As it runs (if I could get it to run), there would be an applet on the page ..


What page? Did the user click a link to get to the page? If so, change that 'link to applet page' to a 'link to JNLP' and the end user will have the same experience, except that.

  • The free floating 'name/choose a color' screen is either resizable (difficult in a web page) or the exact size it needs to be (even harder in a web page).
  • Neither the end user nor you have to deal with applet/JRE/browser interaction problems.
  • JWS can also perform desktop integration (desktop shortcut, start menu item), automatic updates or updates under programmatic control, sand-boxed access to the local file system, a built-in persistence service (to save high scores) ..and a dozen other nice little tweaks that I thought I took the time to mention in that page on JWS I linked to.

  • Did you actually read it?
    J R Hatch
    Greenhorn

    Joined: Sep 07, 2011
    Posts: 26
    Andrew Thompson wrote:
    J R Hatch wrote:
    Andrew Thompson wrote:It would be a better experience for the end user if the frame(s) were launched using Java Web Start.

    I don't say you're wrong, but why? As it runs (if I could get it to run), there would be an applet on the page ..


    What page? Did the user click a link to get to the page? If so, change that 'link to applet page' to a 'link to JNLP' and the end user will have the same experience, except that.

  • The free floating 'name/choose a color' screen is either resizable (difficult in a web page) or the exact size it needs to be (even harder in a web page).
  • Neither the end user nor you have to deal with applet/JRE/browser interaction problems.
  • JWS can also perform desktop integration (desktop shortcut, start menu item), automatic updates or updates under programmatic control, sand-boxed access to the local file system, a built-in persistence service (to save high scores) ..and a dozen other nice little tweaks that I thought I took the time to mention in that page on JWS I linked to.

  • Did you actually read it?


    No, because I know what a web start application is. The page containing the applet was to be a page with other things on it as well, I have the size I want, I don't need desktop integration, and etc.

    But fine, I'll figure out how to do that next. I've tried the basic setup from your link and the tutorials and I keep getting redirected from the launch button to the Java page to download and install the latest Java plugin which I've already installed, so I must be doing the jnlp file incorrectly. I'll figure out how to fix that, I promise. Meanwhile, can you or someone else answer my original question? For all I know, when I run the web start application it will also only open a single dot frame, too.
    Andrew Thompson
    Ranch Hand

    Joined: Aug 05, 2010
    Posts: 77
        
        5
    J R Hatch wrote:.. can you or someone else answer my original question? ..


    I had not looked closely at it thus far, wanted to explore the webstart option first.

    As to the problem with your current code, a glance at the original post suggests it has 2 or more source files, I might have time to look at it if you can post an SSCCE.
     
    With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
     
    subject: using an applet to open another window (JFrame)