-1
I am 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 perfectly, so I just need to know how to call it by a Jbutton.
Follows browser constructor 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 made and I need to call the class above by means of an actionPerformed. What code do I use to accomplish this?
Follows actionPerformed of Jbutton:
private void btnNavegadorActionPerformed(java.awt.event.ActionEvent evt) {
/*
Call browser
Code here
*/
}
You want to open an executable by passing parameters via java?
– user28595
I want to open the class above, by means of a button
– Vinicius Viana
Start by initializing the screen inside the constructor and remove this main ai. The main should only exist in the main application class.
– user28595
then I must instantiate the class in the button actionPerformed?
– Vinicius Viana
Not quite what I said, I will try to answer, although the question does not have an executable code.
– user28595
I have to put the code that builds the frame and the function that returns the browser inside the constructor?
– Vinicius Viana
See the answer below, was what gave to respond with the past information.
– user28595