Saturday, March 5, 2011

Kamehasutra 2 Dragonball Z



Web Browser

Let's see how we can display web pages from Java, you can also view the full page flash with javascript, etc.

All this thanks to a Native library called Swing, can be downloaded from its official website SouceForce here. Images







Code


Master Class


Classes package;


import java.awt.BorderLayout;


import javax.swing.*;
import chrriis.common.UIUtils;
import chrriis.dj.nativeswing.swtimpl.NativeInterface;
import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;


public class Principal extends JFrame {


  public Principal() {
    JPanel webBrowserPanel = new JPanel(new BorderLayout());
    final JWebBrowser webBrowser = new JWebBrowser();
    webBrowser.navigate("http://www.java-elrincondetucasa.blogspot.com");
    webBrowserPanel.add(webBrowser);
    add(webBrowserPanel);
  }
  
  public static void main(String[] args) {
    UIUtils.setPreferredLookAndFeel();
    NativeInterface.open();
    SwingUtilities.invokeLater(new Runnable() {
      public void run() {
     Principal p=new Principal();
     p.setVisible(true);
     p.setBounds(0,0,400,400);
     p.setDefaultCloseOperation(EXIT_ON_CLOSE);

}});
NativeInterface.runEventPump ();
}}


first thing to do when working with libraries, is imported into our project in this case we need three libraries, two coming in NativeSwing folder, you can download from the link at the top, and the other is the SWT library This can be downloaded from the here.

Now if the code to create the browser have to create a JWebBrowser class object, this object will pass the url we want to open with the navigate method ("URL"), then we add this object to the panel.

Finally the main method of the program, you must call the following methods UIUtils.setPreferredLookAndFeel () and NativeInterface.open (); then call the constructor of the Principal but within a Swing separate thread because it has problems when multiple threads try to modify the interface and has internal JWebBrowser several updated several times a thread may have interface problems, to avoid this problem using the method of invokeLater SwingUtilities and finally you must call the method NativeInterface.runEventPump ();

0 comments:

Post a Comment