admin管理员组

文章数量:1531406

2024年5月9日发(作者:)

杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料

1.1 跟我学如何应用DJ Native Swing 组件实现在Java应用程序中嵌入浏览

1、应用DJ Native Swing 组件(/ns/)组件可以支持

Firefox浏览器

2、代码示例

import Layout;

import ;

import ;

import tilities;

import s;

import Interface;

import owser;

public class EagleBrowser extends JPanel {

private JPanel webBrowserPanel;

private JWebBrowser webBrowser;

private String url;

public EagleBrowser(String url) {

杨教授工作室,版权所有,盗版必究, 1/5页

杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料

super(new BorderLayout());

= url;

webBrowserPanel = new JPanel(new BorderLayout());

webBrowser = new JWebBrowser();

te(url);

tonBarVisible(false);

uBarVisible(false);

sVisible(false);

tusBarVisible(false);

(webBrowser, );

add(webBrowserPanel, );

}

public static void main(String[] args) {

final String url = "";

final String title = "电信营业厅缴费终端";

ferredLookAndFeel();

();

Later(new Runnable() {

public void run() {

JFrame frame = new JFrame(title);

aultCloseOperation(_ON_CLOSE);

tentPane().add(new EagleBrowser(url), );

endedState(ZED_BOTH);

ationByPlatform(true);

//ecorated(true);

ible(true);

}

});

杨教授工作室,版权所有,盗版必究, 2/5页

杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料

ntPump();

}

}

3、主要的组件及功能

(1)JWebBrowser

1) Simple Example: This is a simple example that shows the basic configuration of an

embedded web browser component.

2) Setting Content: Set any HTML content to the web browser.

3) Javascript Execution: Execute some Javascript code in the current web browser page.

4) Navigation Control: Control the navigation happening in the web browser from the Java

application.

5) This allows to block certain links and/or the creation of new windows, or to open links

and/or new windows elsewhere.

6) Sending Commands: Use static links or simple Javascript to send some commands with

arguments to the application:

function sendCommand(command) {

var s = 'command://' + encodeURIComponent(command);

for(var i=1; i<;

s+='&'+encodeURIComponent(arguments[i++]));

on = s;

}

1) Cookies: Access and modify the cookies set by the various browser instances.

2) Classpath pages: Load web pages from the classpath with the help of the embedded simple

web server.

3) Mozilla XPCOM Page Edition: Toggle edition mode of a web page by accessing the

Mozilla interfaces using XPCOM.

4) Mozilla XPCOM Download Manager: Modify the browser's download manager

using Mozilla XPCOM.

杨教授工作室,版权所有,盗版必究, 3/5页

杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料

(2)JFlashPlayer

1) Simple Example: Display a Flash application.

2) Variables and Flow: Control the flow of a Flash animation, and get/set global variables.

3) Function Calls: Invoke functions, with or without waiting for a result, and listen to Flash

commands.

(3)JVLCPlayer

Simple Example: Load a movie/sound file to an embedded VLC player.

(4)JHTMLEditor

1) Simple Example: Graphically edit some HTML, get and set the HTML content.

2) Custom Configuration: Modify default behaviors with custom configuration script.

3) TinyMCE implementation: Use the TinyMCE editor implementation instead of the default

FCKeditor.

(5)JSyntaxHighlighter

Simple Example: Display some content with syntax highlighting from one of the available

languages (C++, C#, css, Delphi, Java, JS, PHP, Python, Ruby, SQL, VB, XML, HTML).

(6)JWMediaPlayer (win32)

Simple Example: Load a movie/sound file to an embedded multimedia player.

(7)Additional Features

1) Constrain Visibility: Constrain the visibility to superimpose Swing and native components.

2) Deferred Destruction: Defer destruction until finalization to add/remove the same

is not destroyed when removed but on disposeNativePeer() or garbage

collection.

3) Hierarchy Proxying: Use a proxied component hierarchy for the native components to

allow re-parenting and change of component Z-order.

4) Thumbnail Creation: Create a thumbnail by painting a native component to an image.

5) Pseudo Transparency: Simulate alpha blending of a Swing component over a native

component. This works rather well over static content.

6) Component Life Cycle: Present the life cycle of a component and when method calls

杨教授工作室,版权所有,盗版必究, 4/5页

杨教授工作室 精心创作的优秀程序员 职业提升必读系列资料

highlight how runInSequence(Runnable) can be useful, and for special needs

how to use initializeNativePeer().

(8)Utilities File Associations

Get the file type associations, and use them to launch files.

4、运行示例

(1)java –jar

(2)结果示图

杨教授工作室,版权所有,盗版必究, 5/5页

本文标签: 应用程序组件示例工作室程序员