JFrame 上的 Youtube 视频?
Youtube video on JFrame?
我正在尝试使用 DJ Native Swing API 在我的代码上打开 WebBrowser:
public class YoutubeViewer {
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(null), 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(String trailer) {
trailer = "https://www.youtube.com/watch?feature=player_detailpage&v=6kw1UVovByw";
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JWebBrowser webBrowser = new JWebBrowser();
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
webBrowser.navigate(trailer);
return webBrowserPanel;
}
}
但我不断收到此错误:
谁能帮帮我?
当 class 加载程序(解释器的模块)没有在 class 路径中找到相应的 class(在您的情况下是 SWTNativeInterface)时,会导致这种异常.您应该将相应的库放在项目的 class 路径中。
您在项目属性中设置此 class 路径。
我正在尝试使用 DJ Native Swing API 在我的代码上打开 WebBrowser:
public class YoutubeViewer {
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(null), 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(String trailer) {
trailer = "https://www.youtube.com/watch?feature=player_detailpage&v=6kw1UVovByw";
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JWebBrowser webBrowser = new JWebBrowser();
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
webBrowser.navigate(trailer);
return webBrowserPanel;
}
}
但我不断收到此错误:
谁能帮帮我?
当 class 加载程序(解释器的模块)没有在 class 路径中找到相应的 class(在您的情况下是 SWTNativeInterface)时,会导致这种异常.您应该将相应的库放在项目的 class 路径中。
您在项目属性中设置此 class 路径。