Teach you how to start Java swing's first embedded web

Source: Internet
Author: User
1. I found an open-source project djproject, which is embedded with a browser in swing. It can execute simple JavaScript code in the browser and play other functions such as flash. For some source code, download http://gongqi.iteye.com/blog/754231.

2. To begin.

3. Copy a demo on the Internet and test it. The plug-in package DJNativeSwing-SWT.jar and djnativeswing. Jar need to be introduced

An error occurred while running.

Error message: exception in thread "Main" Java. Lang. noclassdeffounderror: ORG/Eclipse/SWT

Http://ishare.iask.sina.com.cn/download/explain.php? Fileid = 20122660 download the SWT. jar package and introduce it to eclipse.

An error occurred while running.

Error message: exception in thread "Main" Java. Lang. illegalstateexception: the version of SWT that is required is 3.7m5 or later!
At chrriis. DJ. nativeswing. swtimpl. Core. swtnativeinterface. initialize _ (swtnativeinterface. Java: 209)
At chrriis. DJ. nativeswing. swtimpl. nativeinterface. initialize (nativeinterface. Java: 71)
At chrriis. DJ. nativeswing. swtimpl. Core. swtnativeinterface. Open _ (swtnativeinterface. Java: 332)
At chrriis. DJ. nativeswing. swtimpl. nativeinterface. Open (nativeinterface. Java: 100)
At demo1.simplewebbrowserexample. Main (simplewebbrowserexample. Java: 54)

Search online and find the region.

There is an answer from the original provider of djnativeswing.

According to his answer, it means that the introduced SWT package requires version 3.7m5 and later.

4. Therefore, go to http://www.java2s.com/code/jar/s/swt.htmand there are different regions on the network, different system swtpackets,

Download the 3.7m7 SWT. jar package on this website and introduce it to eclipse.

5. Run the program. Binggo. Successful.

The result is as follows:

Attached source code:

<Java>

package demo1;/** Christopher Deckers ()* http://www.nextencia.net** See the file "readme.txt" for information on usage and redistribution of* this file, and for a DISCLAIMER OF ALL WARRANTIES.*/import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import javax.swing.BorderFactory;import javax.swing.JCheckBox;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.SwingUtilities;import chrriis.common.UIUtils;import chrriis.dj.nativeswing.swtimpl.NativeInterface;import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;/*** @author Christopher Deckers*/public class SimpleWebBrowserExample extends JPanel { public SimpleWebBrowserExample() {   super(new BorderLayout());   JPanel webBrowserPanel = new JPanel(new BorderLayout());   webBrowserPanel.setBorder(BorderFactory.createTitledBorder("Native Web Browser component"));   final JWebBrowser webBrowser = new JWebBrowser();   webBrowser.navigate("http://www.google.com");   webBrowserPanel.add(webBrowser, BorderLayout.CENTER);   add(webBrowserPanel, BorderLayout.CENTER);   // Create an additional bar allowing to show/hide the menu bar of the web browser.   JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 4, 4));   JCheckBox menuBarCheckBox = new JCheckBox("Menu Bar", webBrowser.isMenuBarVisible());   menuBarCheckBox.addItemListener(new ItemListener() {     public void itemStateChanged(ItemEvent e) {       webBrowser.setMenuBarVisible(e.getStateChange() == ItemEvent.SELECTED);     }   });   buttonPanel.add(menuBarCheckBox);   add(buttonPanel, BorderLayout.SOUTH); } /* Standard main method to try that test as a standalone application. */ public static void main(String[] args) {   UIUtils.setPreferredLookAndFeel();   NativeInterface.open();   SwingUtilities.invokeLater(new Runnable() {     public void run() {       JFrame frame = new JFrame("DJ Native Swing Test");       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       frame.getContentPane().add(new SimpleWebBrowserExample(), BorderLayout.CENTER);       frame.setSize(800, 600);       frame.setLocationByPlatform(true);       frame.setVisible(true);     }   });   NativeInterface.runEventPump(); }}  

</Java>

Note: The source code used in this article is not written by me. This article aims to help beginners solve the same problems as embedded beginners.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.