我想把一段youtube视频直接嵌入intellij的jframe。我添加了以下库:djnativeswing.jar、djnativeswing-swt.jar和swt.jar。我必须编译三个.jar文件。
youtubepplayer\ u swing.java:
public static void main(String[] args) {
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("YouTube Viewer");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.getContentPane().add(getBrowserPanel(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
// don't forget to properly close native components
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
NativeInterface.close();
}
}));
}
public static JPanel getBrowserPanel() {
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JWebBrowser webBrowser = new JWebBrowser();
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
webBrowser.navigate("https://www.youtube.com/v/b-Cr0EWwaTk?fs=");
return webBrowserPanel;
}
错误:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/jna/Native
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent.getHandle(SWTNativeComponent.java:948)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent.createNativePeer(SWTNativeComponent.java:1006)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent.access$17(SWTNativeComponent.java:989)
at chrriis.dj.nativeswing.swtimpl.core.SWTNativeComponent$12.run(SWTNativeComponent.java:882)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Native
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 18 more
Process finished with exit code 0
我做错什么了?
1条答案
按热度按时间xxls0lw81#
您使用哪个版本的jar文件?我可以使用djnativeswing-swt-1-0-2成功运行您的代码(例如
DJNativeSwing.jar
以及DJNativeSwing-SWT.jar
)和swt-4.5-win32-win32-x86_64(用于swt.jar
).这个堆栈溢出答案描述了一个类似的场景,可能对您很有用。