I'm building a java application that has a browser built through a java class.
I want to know how I can call this class (executable class) through an actionPerformed of a JButton, that is, when I click a button I want the browser to be built by the class and initialized.
Without the button call the browser works fine, so I just need to know how to call it by a JButton.
Follow the browser builder class:
package view;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
public class YoutubeViewer{
public static String url;
public YoutubeViewer(String url) {
this.url = url;
}
public static void main(String[] args) {
NativeInterface.open();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Reprodução de Áudio/Vídeo");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(getBrowserPanel(), BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
NativeInterface.runEventPump();
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
NativeInterface.close();
}
}));
}
public static JPanel getBrowserPanel() {
url = "https://www.youtube.com/v/UWz_Sqj-mvI";
JPanel webBrowserPanel = new JPanel(new BorderLayout());
JWebBrowser webBrowser = new JWebBrowser();
webBrowserPanel.add(webBrowser, BorderLayout.CENTER);
webBrowser.setBarsVisible(false);
webBrowser.navigate(url);
return webBrowserPanel;
}
}
I have a button already done and need to call the above class via an actionPerformed. What code do I use to accomplish this?
Following the actionPerformed of the JButton:
private void btnNavegadorActionPerformed(java.awt.event.ActionEvent evt) {
/*
Call browser
Code here
*/
}