在swing界面中嵌入javaFX运行的视频

javaFx2.0的出现让我迅速把注意力又转回javaFx,oracle做的不错,实现javaFX可以用钟爱的java了,看了它的实例也非常不错。
正好我在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
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* 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);
}
//</editor-fold>
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的技术问题
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值