我喜欢旧的Java小程序。但是因为我非常喜欢JFX的工作方式,我想用它来写一些游戏(甚至是游戏制作系统,谁知道?),但我希望能够在我的网站上发布它们。怎么会这样做?
答案 0 :(得分:4)
是的,您应该能够在您的网页中嵌入JavaFX:
http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/deployment_toolkit.html#BABJHEJA
http://docs.oracle.com/javase/8/javase-clienttechnologies.htm
答案 1 :(得分:4)
是的,您可以将JavaFX GUI嵌入到基于Swing的JApplet中。您可以使用JFXPanel来完成此操作 - 它本质上是Swing和JavaFX面板之间的适配器。
完整示例:
设置JavaFX GUI的FXApplet
类:
public class FXApplet extends JApplet {
protected Scene scene;
protected Group root;
@Override
public final void init() { // This method is invoked when applet is loaded
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initSwing();
}
});
}
private void initSwing() { // This method is invoked on Swing thread
final JFXPanel fxPanel = new JFXPanel();
add(fxPanel);
Platform.runLater(new Runnable() {
@Override
public void run() {
initFX(fxPanel);
initApplet();
}
});
}
private void initFX(JFXPanel fxPanel) { // This method is invoked on JavaFX thread
root = new Group();
scene = new Scene(root);
fxPanel.setScene(scene);
}
public void initApplet() {
// Add custom initialization code here
}
}
它的测试实现:
public class MyFXApplet extends FXApplet {
// protected fields scene & root are available
@Override
public void initApplet() {
// this method is called once applet has been loaded & JavaFX has been set-up
Label label = new Label("Hello World!");
root.getChildren().add(label);
Rectangle r = new Rectangle(25,25,250,250);
r.setFill(Color.BLUE);
root.getChildren().add(r);
}
}
或者,您可以使用FXApplet
gist,其中还包含一些文档。