1

I am trying to create an applet that will replace a confusing CLI with a nice JavaFX GUI. I don't have extensive experience with GUI design and most of what we learned in the classroom environment was Swing/AWT. Having toyed a little bit with JavaFX, I feel that it has already shown to be far better, however there aren't many good tutorials/articles out there about creating JavaFX programs intended to run as applets. Right now I can't even seem to convert the following simple login UI from Swing to JavaFX.

import java.applet.Applet;
import java.awt.*;
import javax.swing.*;


public class ACLEditor extends Applet {

    public void init() {

        /* Basic Layout */
        setLayout(new GridLayout(5, 2));

        /* Components */
        JLabel username_l = new JLabel("Username:");
        JTextField username = new JTextField("", 10);
        JLabel password_l = new JLabel("Password:");
        JPasswordField password = new JPasswordField("", 10);
        JLabel hostname_l = new JLabel("Hostname:");
        JTextField hostname = new JTextField("0.0.0.0", 10);

        JButton connect_btn = new JButton("Connect");

        /* Place all Controls on the Layout */
        add(username_l);
        add(username);
        add(password_l);
        add(password);
        add(hostname_l);
        add(hostname);
        add(connect_btn);

    }


}

Any help on this would be appreciated. Note: I do understand how to create a JavaFX UI for a standalone application, I just can't seem to grasp how to make it into an applet

Zoe
  • 27,060
  • 21
  • 118
  • 148
  • Applets are sort-of discouraged as it's so hard to make them work with browser security. "How to deploy a JavaFX application as an applet" would probably take too much to write as a full SO answer, but there is a deployment guide [here](http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm) which includes applet deployment. – James_D Aug 11 '14 at 20:11
  • Yeah, I came across the browser security issue a few times with my "untrusted application" and tried to complete the project using HTML5 + WebSockets just to fail miserably. Applets are the best Java implementation I have managed to pull-off (aka understand) so far so I'm 'stuck' using them, if that makes sense. – Cold cup of Java Aug 11 '14 at 20:41

2 Answers2

1

As of JavaFX 8, you can deploy a JavaFX app in some desktop browsers using the JavaFX packaging tools and deployment toolkit. There are caveats regarding this approach. A brief description of some of these and summary of how to deploy is in: JavaFX - can it really be deployed in a browser?.

You don't need a JFXPanel to achieve this and I wouldn't recommend one unless your app also used Swing controls.

Community
  • 1
  • 1
jewelsea
  • 150,031
  • 14
  • 366
  • 406
0

After looking around more, it seems the best way to incorporate JavaFX elements into a project that uses Swing UI architecture (like my little applet) is to place those elements on a JFXPanel.

http://docs.oracle.com/javafx/2/api/javafx/embed/swing/JFXPanel.html

This will allow the applet to be deployed in the same fashion as it was originally, while also adding nice looking JavaFX components to the GUI.