DOC

3348.docjava

By Jessica Taylor,2014-10-15 23:02
11 views 0
3348.docjava

    由于程序的原因:本文件未被完整保存。

    首页 ? 研究文集 ? Java GUI

    SWT+JMF乱真windows播放器 Zergling 原创 (参与分;12866:专家分;115) 发表;2003-07-22 21:03 更新;2003-07-23

     14:48 版本;1.0 阅读;5784

    SWT的最大好处是windows具有窗口风格:把SWTJMF结合使用:windows的外框:java的播放器:你觉得

    我这个想法如何~

    如果你要运行我的代码:你必须安装JMF2.1.1e并且将swtjar文件导入(记得要将swt-win32-2135.dll

    在执行路径下)

    1. import java.awt.BorderLayout;

    2. import java.awt.Component;

    3. import java.awt.Panel;

    4. import java.io.IOException;

    5. import java.net.MalformedURLException;

    6. import java.net.URL;

    7.

    8. import javax.media.ConfigureCompleteEvent; 9. import javax.media.ControllerEvent;

    10.import javax.media.ControllerListener;

    11.import javax.media.EndOfMediaEvent; 12.import javax.media.Manager;

    13.import javax.media.NoPlayerException;

    14.import javax.media.Player;

    15.import javax.media.RealizeCompleteEvent; 16.

    17.import org.eclipse.jface.window.Window; 18.import org.eclipse.swt.SWT;

    19.import org.eclipse.swt.internal.awt.win32.SWT_AWT; 20.import org.eclipse.swt.widgets.Display; 21.import org.eclipse.swt.widgets.Shell;

    22.

    23./**

    24. * @author

    25. * <a >刘洋</a>

    26. * 2003-7-17 19:34:38

    27. */

    28.public class SWTPlayer implements ControllerListener { 29.

    30. public static void main(String[] args) { 31. SWTPlayer sp = new SWTPlayer(); 32. sp.play();

33. }

    34. private boolean configured =false; 35. private boolean realized = false; 36. Player player;

    37. Panel panel;

    38. public void play(){

    39. Display display = new Display (); 40. Shell shell = new Shell(display,SWT.MAX); 41. shell.setSize(320,240);

    42. shell.setText("你好SWT");

    43. panel = SWT_AWT.new_Panel(shell); 44. URL url = null;

    45. try {

    46. url = new URL("file:/D:/video/jboss.mpeg");

    47. } catch (MalformedURLException e) { 48. e.printStackTrace();

    49. }

    50. try {

    51. player = Manager.createPlayer(url); 52. } catch (NoPlayerException e1) { 53. e1.printStackTrace();

    54. } catch (IOException e1) { 55. e1.printStackTrace();

    56. }

    57.

    58. player.addControllerListener(this); 59.

    60. player.realize();

    61. while (! realized) {

    62. try {

    63. Thread.sleep(100L);; 64. } catch (InterruptedException e) { 65. // ignore

    66. }

    67. }

    68. panel.setLayout(new BorderLayout()); 69. panel.add(player.getVisualComponent(),BorderLayout.CENTER);

    70. Component cpc = player.getControlPanelComponent();

    71. if (cpc != null) {

    72. panel.add(cpc,BorderLayout.SOUTH); 73. } else {

    74.

    75. }

    76. player.start();

77.

    78. shell.open ();

    79. Window win;

    80.

    81. while (!shell.isDisposed ()) {

    82. if (!display.readAndDispatch ()) display.sleep (); 83. }

    84. display.dispose ();

    85. }

    86. /* (non-Javadoc)

    87. * @see javax.media.ControllerListener#controllerUpdate(javax.media.ControllerEvent)

    88. */

    89. public void controllerUpdate(ControllerEvent evt) { 90. if (evt instanceof RealizeCompleteEvent) { 91. realized = true;

    92. } else if (evt instanceof ConfigureCompleteEvent) { 93. configured = true;

    94. } else if (evt instanceof EndOfMediaEvent) { 95. } else {

    96. }

    97. }

    98.}

    版权声明 给作者写信 本篇文章对您是否有帮助~ 投票; 投票结果;

    作者其它文章;

    ; DOM4J中使用XPath

    ; J2ME编程实例之数字键测试

    作者全部文章

    上一篇文章 下一篇文章 返回〔Java GUI

Report this document

For any questions or suggestions please email
cust-service@docsford.com