正好我在swing开发中需要嵌入视频,看javaFx的实例里就有,于是仿照这个实现一下。
其间经历了不少挫折。但最后还是搞成了。
写一下嵌入的注意事项:
1、javaFx实例中的AdvancedMedia是 extends的 javaFX里的Application这个类。Application负责掌管了视频的几个线程的启动等。
2、swing要嵌入FX组件只有一种方式就是用JFXPanel嵌入sense。这样的矛盾就不能嵌入我需要的视频了?
3、经过研究发现,可以通过AdvancedMedia继承一个applet的方式实现。
@Override public void init() { /* * Set the Nimbus look and feel */ ///* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJApplet.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } // initComponents(); jfxp = new JFXPanel(); jfxp.setPreferredSize(new Dimension(400, 300)); jPanel1.setLayout(new BorderLayout()); jPanel1.add(jfxp, BorderLayout.CENTER); /* * Create and display the applet */ Platform.runLater(new Runnable() { @Override public void run() { createScene(); } }); }
呵呵,这样巧妙的通过run方法里加入了sense。终于实现了。
附上我实现的源码,件附件
还有我的qq:471016340探讨javaFX的技术问题