Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the collection and development method of JavaFX WebView?

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what is the collection and development method of JavaFX WebView". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the collection and development method of JavaFX WebView"?

Background

Recently want to do a desktop version of the client, can load connections, access to source code, etc., mainly used for quick access to the website column, then with the crawler under the column of the latest information.

Adopt technology

Java 1.8

Introduction of related plug-ins

JavaFX is:

A software platform for creating and delivering desktop applications, as well as rich Internet applications (RIA) that can run on a variety of devices.

A set of graphics and media packs that enable developers to design, create, test, debug, and deploy rich client applications that run consistently on different platforms.

WebView:

Using the Web component of WebKit HTML technology, you can embed Web pages in JavaFX applications. A JavaScript running in WebView can call Java API,Java API or a JavaScript running in WebView.

JavaFX adds support for other HTML5 features, including Web sockets, Web Worker and Web fonts, and printing.

JavaFX WebView:

JavaFX WebView is a mini-browser (also known as an embedded browser) that provides Web viewer and full browsing capabilities through API in JavaFX applications.

This browser is based on WebKit, an open source Web browser engine that supports HTML5,JavaScript,CSS,DOM rendering and SVG graphics.

The WebView class is an extension of the Node class.

The embedded browser inherits all the fields and methods from the Node class, so it has all its functions.

It encapsulates WebEngine objects, merges HTML content into the application's scenario, and provides properties and methods for applying effects and transformations.

The getEngine () method called on the WebView object returns the Web engine associated with it.

The classes that make up the embedded browser are in the javafx.scene.web package.

WebView enables developers to implement the following functions in their Java applications:

◦ renders HTML content from local or remote URL

◦ supports history and provides backward and forward navigation

◦ reloads content

◦ applies the effect to the Web component

◦ Editing HTML content

◦ executes the JavaScript command

◦ executes the uplink call from JavaScript to JavaFX

◦ handles events

In addition to supporting CSS3 and ecmascript6 (ES6), the WebView component also supports the following HTML5 features:

◦ DOM3

◦ canvas

◦ media playback

◦ form controls (except)

◦ editable content

◦ history maintenance

◦ support, and tags

◦ SVG

◦ Web socket

◦ Web Worker

◦ supports domain names written in the native language

Web engine:

1. Is a non-visual object that can manage one web page at a time

two。 Provides basic web page functions through its API.

3. It supports user interactions, such as navigating links and submitting HTML forms, but it does not interact directly with the user.

4. It loads a web page, creates a document model, applies styles as needed, and runs JavaScript on the page.

5. It provides access to the document model of the current page and allows two-way communication between the Java application and the JavaScript code of the page.

6. It wraps a WebPage object that provides interaction with the native Webkit core.

Main code introduction:

Main interface construction:

Package org.lc.v1

Import org.lc.v1.component.WebBrowerPane

Import org.lc.v1.handle.AlertEventHandler

Import org.lc.v1.handle.PopupCallback

Import org.lc.v1.html.HtmlChangeListener

Import org.lc.v1.html.WebHistoryVisitListener

Import javafx.application.Application

Import javafx.scene.Scene

Import javafx.scene.control.Tab

Import javafx.scene.web.WebEngine

Import javafx.scene.web.WebHistory

Import javafx.scene.web.WebView

Import javafx.stage.Stage

Public class LCWebBrower extends Application {public void start (Stage stage) throws Exception {final WebBrowerPane tp = new WebBrowerPane (stage)

Stage.setScene (new Scene (tp, 950,600))

Final WebView webView = new WebView ()

WebView.prefWidthProperty () .bind (stage.getScene () .widthProperty ())

WebView.prefHeightProperty () .bind (stage.getScene () .heightProperty ())

Final WebEngine webEngine = webView.getEngine ()

Final WebHistory history = webEngine.getHistory ()

History.getEntries () .addListener (new WebHistoryVisitListener ()

WebEngine.getLoadWorker (). StateProperty (). AddListener (new HtmlChangeListener (webEngine))

WebEngine.setOnAlert (new AlertEventHandler (tp))

WebEngine.setCreatePopupHandler (new PopupCallback (tp))

WebEngine.setJavaScriptEnabled (true)

WebEngine.executeScript ("location.reload (true);")

WebEngine.load ("loaded address")

Final Tab tab = new Tab ()

Tab.textProperty () .bind (webEngine.titleProperty ()

Tab.setClosable (false)

Tab.setContent (webView)

Tp.addTabPage (tab)

Stage.show ()

} public static void main (String [] args) {

Launch (args)

}

}

Monitoring does not load the status, get the source code, all connections, and so on.

Package org.lc.v1.html

Import org.w3c.dom.NamedNodeMap

Import org.w3c.dom.Node

Import org.w3c.dom.NodeList

Import javafx.beans.value.ChangeListener

Import javafx.beans.value.ObservableValue

Import javafx.concurrent.Worker.State

Import javafx.scene.web.WebEngine

Public class HtmlChangeListener implements ChangeListener {

Private WebEngine webEngine

String html

Public HtmlChangeListener (WebEngine webEngine) {

This.webEngine = webEngine

}

Public void changed (ObservableValue

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report