欢迎来到天天文库
浏览记录
ID:24453191
大小:38.50 KB
页数:2页
时间:2018-11-14
《java播放flash》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java播放flash其实不难,具体的实现已经由jflashplayer.jar包装好,由FlashPanel根据文件创建新的对象,然后窗口绑定该容器对象即可播放。至于jflashplayer.jar百度应该会有,java不自带,去csdn应该有资源。FlashPlayer.Java:importjava.io.File;importjava.io.FileNotFoundException;importcom.jpackages.jflashplayer.FlashPanel;importcom.jpackages.jflashplayer.JFlashInvalidFlashExcept
2、ion;importcom.jpackages.jflashplayer.JFlashLibraryLoadFailedException;publicclassFlashPlayer{privateStringfileName;//播放文件名privateStringflashfolder;//播放文件夹publicFlashPanelflashPanel;//flash容器publicStringgetFileName(){returnfileName;}publicvoidsetFileName(StringfileName){this.fileName=fileName;}publi
3、cStringgetFlashfolder(){returnflashfolder;}publicvoidsetFlashfolder(Stringflashfolder){this.flashfolder=flashfolder;}publicvoidplay(){if(flashfolder!=null&&fileName!=null){try{flashPanel=newFlashPanel(newFile(flashfolder+'/'+fileName));//根据文件新建FlashPanel对象flashPanel.setBounds(0,0,260,60);}catch(Fil
4、eNotFoundExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(JFlashLibraryLoadFailedExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}catch(JFlashInvalidFlashExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}ThreadplayThread=newThread(newPlayThread());play
5、Thread.start();}}publicclassPlayThreadextendsThread{publicvoidrun(){flashPanel.play();}}}Test.java:importjava.awt.GridBagConstraints;importjava.awt.GridBagLayout;importjavax.swing.JFrame;importjavax.swing.JPanel;publicclassTestextendsJFrame{publicGridBagLayoutlayout=newGridBagLayout();//可变布局publicG
6、ridBagConstraintsconstraints=newGridBagConstraints();//布局设置publicFlashPlayerflashPlayer=newFlashPlayer();/***@paramargs*/publicTest(){JPaneljp=newJPanel();jp.setLayout(layout);flashPlayer.setFlashfolder("src/flash");flashPlayer.setFileName("猜词飞天小女警版.swf");flashPlayer.play();constraints.fill=GridBag
7、Constraints.BOTH;//组件随显示变化的选项constraints.weightx=1;//水平扩展,即显示变化时,长度变化constraints.weighty=1;//垂直扩展,即高度变化constraints.anchor=GridBagConstraints.CENTER;layout.setConstraints(flashPlayer.flashPanel,constraints);
此文档下载收益归作者所有