java djnativeswing,用过DJNativeSwing-SWT进来看看, 帮帮忙.解决办法

Java codepackage com.jj;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import java.awt.GridLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.util.ArrayList;

import java.util.List;

import javax.swing.BorderFactory;

import javax.swing.JButton;

import javax.swing.JCheckBox;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.SwingUtilities;

import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;

import org.eclipse.swt.widgets.MessageBox;

//import com.birosoft.liquid.LiquidLookAndFeel;

import chrriis.common.UIUtils;

import chrriis.dj.nativeswing.swtimpl.NativeInterface;

import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserCommandEvent;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserEvent;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserListener;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserNavigationEvent;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowOpeningEvent;

import chrriis.dj.nativeswing.swtimpl.components.WebBrowserWindowWillOpenEvent;

/**

* @author Christopher Deckers

*/

public class WebBrowserExample extends JPanel {

final static JWebBrowser webBrowser = new JWebBrowser();

static String javascript = "alert('alert111');";

public WebBrowserExample(String url) {

super(new BorderLayout());

JPanel webBrowserPanel = new JPanel(new BorderLayout());

webBrowserPanel.setBorder(BorderFactory

.createTitledBorder("Native Web Browser component"));//

webBrowser.navigate(url); //

// webBrowser.setBarsVisible(false);

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

JButton home = new JButton("主页");

JButton forward = new JButton("前进");

JButton back = new JButton("后退");

JButton flush = new JButton("刷新");

JButton stop = new JButton("停止");

webBrowser.addWebBrowserListener(new WebBrowserListener() {

public void windowWillOpen(WebBrowserWindowWillOpenEvent arg0) {

// System.out.println("��ǰ��ҳURL:"+arg0.getWebBrowser().getResourceLocation()

// );

// System.out.println("Ҫ��ת��ҳURL:"+arg0.getWebBrowser().getStatusText()

// );

webBrowser.navigate(arg0.getWebBrowser().getStatusText());

arg0.consume();

}

public void windowOpening(WebBrowserWindowOpeningEvent arg0) {

}

public void windowClosing(WebBrowserEvent arg0) {

}

public void titleChanged(WebBrowserEvent arg0) {

}

public void statusChanged(WebBrowserEvent arg0) {

}

public void locationChanging(WebBrowserNavigationEvent arg0) {

}

public void locationChanged(WebBrowserNavigationEvent arg0) {

}

public void locationChangeCanceled(WebBrowserNavigationEvent arg0) {

}

public void loadingProgressChanged(WebBrowserEvent arg0) {

}

public void commandReceived(WebBrowserEvent arg0, String arg1,

String[] arg2) {

}

public void commandReceived(WebBrowserCommandEvent arg0) {

// TODO Auto-generated method stub

}

});

buttonPanel.add(home);

buttonPanel.add(back);

buttonPanel.add(forward);

buttonPanel.add(flush);

buttonPanel.add(stop);

home.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

webBrowser.navigate("www.163.com");

}

});

forward.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

webBrowser.navigateForward();

}

});

back.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

webBrowser.navigateBack();

}

});

flush.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

webBrowser.reloadPage();

}

});

stop.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

webBrowser.stopLoading();

}

});

add(buttonPanel, BorderLayout.SOUTH);

SwingUtilities.invokeLater(new Runnable() {

public void run() {

webBrowser.executeJavascript(javascript); //执行JavaScript

}

});

NativeInterface.open();

NativeInterface.runEventPump();

}

/* Standard main method to try that test as a standalone application. */

public static void main(String[] args) {

ReadJS rjs = new ReadJS();

// javascript = rjs.readFileByLines("./javascipt1.js");

System.out.println(javascript);

JFrame frame = new JFrame("DJ Native Swing Test");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

WebBrowserExample wbe = new WebBrowserExample("http://www.baidu.com");

frame.add(wbe, BorderLayout.CENTER);

// frame.setUndecorated(true);

// frame.setSize(1024, 768);

frame.setSize(800, 600);

// frame.setLocationByPlatform(true);

frame.setVisible(true);

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值