Use JDIC to interact with local desktop programs

Source: Internet
Author: User

Java shines on the web, but on the desktopProgramThere are too many weaknesses in development. Swing's default style is ugly and slow. To be compatible with various operating systems, it is difficult for Java to easily interact with proprietary programs in some systems, such as IE in windows. net Framework provides convenient tools for use.

Package local programs, which is also a major idea of software development. For example, the Maxthon browser (formerly myie2) is developed based on IE and adds many functions, it is very popular now.

As you can imagine, it is quite difficult to implement a Maxthon using Java.

However, the emergence of JDIC makes it much easier for Java to interact with the local desktop program. Jdesktop integration components (JDIC) is designed to build components that eliminate gaps between local applications and Java equivalents. JDIC currently provides support for local Web browsers (Internet Explorer or Mozilla), System Tray support, file extension integration, and other desktop features. I believe that JDIC will become increasingly popular in Java Desktop development in the future.

Https://jdic.dev.java.net/
Http://www.ibm.com/developerworks/cn/java/j-jdic/
Http://community.java.net/javadesktop/

The following uses an IE browser-based applet to introduce the use of JDIC.

Program Requirements: Copy a text section to some forms on the Web page played by IE browser to automatically enter the form. For example, we log on to phpeye.com and enter the user logon form automatically.

This function is now supported by many browsers, such as Firefox, which will be recorded and then automatically completed. Of course, program control is more powerful and easy to expand. This is a simple function, but for some industries, you often need to fill in a large number of forms on the web page, it is very useful, can save a lot of time, especially if the entered data is also read by a program :)

Solution:Use the program to open an IE window and execute a javascriptCode, Set the form value.

Use the JDIC package org. jdesktop. JDIC. browser, and use the executescript () method to execute Javascript in the HTML opened in the current window. Here, we can simply rewrite the JDIC. browser demo to meet our needs.

First, add an Automatic completion button in the browser and add an event processing function to the button.

Import org. jdesktop. JDIC. browser .*;

Webbrowser = new webbrowser (new URL ("http://www.phpeye.com "));

Jbutton jcompletebutton = new jbutton ("automatically filled in ",
New imageicon (getclass (). getresource ("images/ac.png ")));

Jcompletebutton. addactionlistener (New browser_jcompletebutton_actionadapter (this ));

Class browser_jcompletebutton_actionadapter implements java. AWT. event. actionlistener {
Browser adaptee;

Browser_jcompletebutton_actionadapter (Browser adaptee ){
This. adaptee = adaptee;
}

Public void actionreceivmed (actionevent e ){
Adaptee. jcompletebutton_actionreceivmed (E );
}
}

Void jcompletebutton_actionreceivmed (actionevent e ){
Webbrowser.exe cutescript ("document. getelementbyid ('uname'). value = 'haohappy'; document. getelementbyid ('pwd'). value = '2016 ';");
}

The red line above uses js to set the content of the form.

Final result:

You can execute JavaScript on the current page to perform various operations on HTML and implement various functions.

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.