2015-11-19 75 views
0

我試圖使用DJ本地Swing的API來打開我的代碼web瀏覽器:JFrame上的Youtube視頻?

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; 
} 
} 

但我不斷收到此錯誤:

http://i.imgur.com/UMUoFS4.png

誰能幫助我?

回答

1

當類加載器(解釋器的模塊)沒有在類路徑中找到相應的類(在您的情況下爲SWTNativeInterface)時,會導致此類異常。您應該將相應的庫放置在項目的類路徑中。

您在項目屬性中設置此類路徑。

+0

它在我的項目的類路徑上。我將DJNativeSwing.jar和DJNativeSwing-SWT.jar添加到我的類路徑中。他們在我的參考圖書館。 –