Use of JDIC

Source: Internet
Author: User

If programmers develop programs on Windows and use JDIC, import relevant jar packages such as JDIC to their projects. jar ., and the JDIC. DLL and tray. place the DLL in the bin directory of the system JRE.

The procedure is as follows:

Excerpt

Related download https://jdic.dev.java.net


This article briefly introduces the use of JDIC (jdesktop integration components) and teaches you how to use JDIC to call or integrate components or applications in the local desktop environment in the form of instances.

If you frequently access java.net or read javaone's news reports, you may have heard of jdesktop integration.
Components (JDIC ). These new APIs allow Java developers to do the things we once envied by our local compatriots. This article will give you a question about JDIC
A comprehensive introduction to features. Each feature has a small example and a list of what to download in the first step. In addition to the sub-project saverbeans
Tested API

Jdesktop Integration
Components, or JDIC, is an all-encompassing project that provides Java developers with access to local features through the delivery platform API. This project is started by the sun desktop Group
The purpose is to enable Java applications to better integrate with their running desktop environments. To get quick feedback on desired features from developers, they made JDIC an open-source project. Although currently
No plan, but the JDIC team is considering adding JDIC features to the future version of the Java core class library.

JDIC is divided into five parts and an incubator project:

L desktop: to open, edit, and use email to mail files to open desktop programs;

L file type: Set desktop file type Association;

L Browser: embed a local browser (Internet Explorer or Mozilla) into the AWT canvas );

L package: the command line tool for program installation at the cost of converting Java Web Start program;

L tray API: supports System Tray icons and pop-up menus;

L saverbeans: System screen protection in Java;

 

Desktop Components
Desktop components are the simplest and most useful JDIC components. It is dedicated to basic desktop services, such as opening a file in the correct Editor, creating an email, or sending a URL
To the default web browser. Building these things requires a lot of work, but it is very easy to use. If you want to tell the operating system to open a Word document, call
Desktop. Open (New file(your resume.doc "); that's it.

The Org. jdesktop. JDIC. desktop package has only three classes: desktop, message, and reply topexception.
The desktop class is static and cannot be instantiated. It has several methods to open, edit, and print files. You can also open a new email and fill it with text. This is the message used
It allows you to set the recipient, email body, attachments, and other parts.

The best thing about the desktop package is how simple it is to use. You do not need to register any special drivers or modify the configurations based on the current platform. All these things have been done behind the scenes
. As long as your JDIC. jar file is in your class path and the local library is in your library path (you usually put it together with the. jar file), the code will work. Below is a worker
Online example of the browser:

Import org. jdesktop. JDIC. desktop .*;
Import java.net .*;
Public class shorttoptest {
Public static void main (string [] ARGs)
Throws exception {
Desktop. Browse (
New URL ("http://www.yahoo.com/

")
);
}
}

File Type Component
The next core component of JDIC is the file type package, which is used to set file type association. This means that you can tell the operating system what files are opened with what program, for example, always open a text file with word instead of opening it with a wordpad. With this API, You can query, set, and delete file type associations based on file extensions and MIME types.

If the file type is usually exclusive to an operating system, this API is more useful when you retrieve the association or register the application itself rather than set the association. For example, in windows
The Association of a common local file is the notepad.exe file in the latest weekly directory. In gnome, it may call/usr/local/bin/gedit. Because this is
In addition to binding Java applications to their own files, setting associations may not be very useful. However, no matter what you do with it, the file type component processes the registry and mime
The data type method handles all the heavy work for you.

Below is a short example of setting file associations:

Import org. jdesktop. JDIC. filetypes .*;
Import java.net .*;
Public class filetypestest {
Public static void main (string [] ARGs)
Throws exception {

Action action = new action ("open ",
"C: windowssystem32
Otepad.exe % 1 ");

Association assoc = new Association ();
Assoc. addfileextension (". mchat ");
Assoc. setmimetype ("application/mad-chatter ");
Assoc. addaction (action );

Associationservice SVC = new associationservice ();
SVC. registeruserassociation (Assoc );

}
}

Create an action that will use notepad.exe to open a file (replace % 1 with) in the actions line of mainstores. The last four lines are in the action and
Files are associated. In the past, most operating systems relied solely on the file extension or all metadata to determine the file type. However, today, most operating systems tend to set
Mime. Therefore, it is helpful to start using it now. The last two rows are actually associated registration on the system. When using all JDIC
When using APIs, you do not need to do anything special as long as the local library is on your library path to make it work.

Browser Components
The third major component of JDIC is the browser component. Unlike the front two, they only allow you to access system services. This component gives you an AWT device that is truly used in graphics applications. Previously, you could
Using third-party embedded components or pure Java browsers, but JDIC allows you to embed users' default web browsers into your applications, which creates many opportunities for us. Now I have written some comprehensive information
The RSS reader supported by the web becomes possible. Because you don't have to include a local browser in your application, the download speed is faster.

The browser component API allows you to access several browser events and control history (forward, backward, and refresh ). The API version that will be revised in the future is expected to provide more access to browsers and arbitrary documents.

It is very easy to use browser components in your application:

Import org. jdesktop. JDIC. browser .*;
Import java.net .*;
Import javax. Swing .*;

Public class browsertest {
Public static void main (string [] ARGs) throws exception {

Webbrowser browser = new webbrowser ();
Browser. seturl (new URL ("http://java.net

"));

Jframe frame = new jframe ("browser test ");
Frame. setdefaclocloseoperation (jframe. exit_on_close );
Frame. getcontentpane (). Add (browser );
Frame. Pack ();
Frame. setsize (500,500 );
Frame. setvisible (true );
}
}

As you can see, the webbrowser object is just an AWT component that you can put into a standard jframe. The first line of the main method creates a new
The second line sets the URL you want to display. Other Code creates a frame, adds the browser to it, and makes the frame visible.

 

Remember that webbrowser is a local AWT component, so you may fall into the dilemma of combining with swing. The two rules for mixing them are:
1) do not overlap swing and AWT components
2) Call setlightweightpopupenabled (false) on your menu; otherwise they will disappear behind the browser component.

Browser components will immediately use your default web browser, which is usually Internet Explorer or Mozilla. You cannot be like using jrex (http://jrex.mozdev.org/

)
Bind the necessary parts of Mozilla with your application. This method may work on Windows. IE is absolutely acceptable, but there are more problems in Linux, because it
The default browser above is not necessarily Mozilla (for example, it may be konquorer on KDE ). We hope these problems can be solved as the project matures, but currently it is very useful for many projects.
Useful.

Package component
Unlike other JDIC, the wrapper module is not an API, but a JNLP (Java Web
Start) a set of command line tools for installing programs (RPMS on Linux, pkgs on Solaris, and MSIS on Windows) at the cost of application conversion. This does not mean
Jsmoothor jexepackconverts your application to .exe; it is only for Web
The Start application provides the click-to-install function. After the program is installed, it will use JNLP to update itself over the Internet and do all other things that the Web Start application can do.

Package components require j2se5.0 and local tools. For Windows, you need to install Microsoft MSI
SDK. Once your environment is established, you can use the command line tool jnlp2msi, JNLP 2rpm, and jnlp2pkg
The Start application is converted into a platform-related installer.

System Tray
The tray icon API was originally an incubation project, but thanks to the diligent efforts of the java.net community, it has matured and elevated it to a complete position as a JDIC component. Assume that your operating system has
Disk concept, it aims to create a applet status icon in the lower right corner of the screen. In fact, such operating systems refer to Windows and Linux. Mac OS
X users do not have this luck. It also supports pop-up menus and provides automatic tool prompts for icons. Like other JDIC, the system tray support requires local code, but you can use Java
API code to use the pre-compiled local library.

Because this API has a very small scope of use, there are only two classes:
Systemtray and trayicon. The systemtray class has a static factory method for accessing the default tray of the system. Trayicon allows you
Jpopupmenu and icon are added to the next available location of the system tray. Finally, call
Systemtray. getdefasystemsystemtray (). addtrayicon () shows your pop-up menu. Let's look at a small example:

Import org. jdesktop. JDIC. Tray .*;
Import java. AWT. event .*;
Import javax. Swing .*;

Public class systemtraytest {
Public static jmenuitem quit;

Public systemtraytest (){
Jpopupmenu menu = new jpopupmenu ("My menu ");
Menu. Add (New jmenuitem ("Test 1 "));
Menu. Add (New jmenuitem ("Test 2 "));
Quit = new jmenuitem ("quit ");
Quit. addactionlistener (New actionlistener (){
Public void actionreceivmed (actionevent EVT ){
System. Exit (0 );
}});

Menu. Add (quit );

Imageicon icon = new imageicon ("duke.gif ");
Trayicon tray_icon = new trayicon (icon, "system tray test! ", Menu );

Systemtray tray = systemtray. getdefasystemsystemtray ();
Tray. addtrayicon (tray_icon );
}
Public static void main (string [] ARGs ){
New systemtraytest ();
}

}

We created a jpopupmenu using three menu items in the rows at the front of the systemtraytest constructor. The last one is quit.
Actionlistener is used to exit the program. Now, in addition to adding the menu to the menu bar and jcomponent, we put the menu into the constructor of trayicon.
. The imageicon that displays the system tray icon, along with the tooltip text, is also transferred to the trayicon. Finally, we add the trayicon to the default systemtray.
The program is complete. Put tray. jar and tray. dll in the class path and library path (usually the working path) respectively ).

 

Trayapi also supports animated GIF icons and left-click actions. With this API, you can display your application on the task bar only when you need it.

Incubator project
From the very beginning, JDIC was designed to actively encourage and develop new APIs. To facilitate project growth, they created incubator projects where developers can submit their code and experiment with their ideas. If their ideas are good and mature, the project can be upgraded to a complete JDIC module or even a new project.

Saverbeans SDK
I used to keep my favorite APIs. Now, JDIC has a major incubator project: a toolkit for creating the screen saver for the delivery platform called saverbeans. Like other JDIC, you
Java can be used for full encoding, allowing the pre-built local database to process a large number of details. This project is composed of an API for processing callback, an XML file for configuration, and a platform supporting file to generate a platform-related screen.
An ant task that protects executable programs (. scr on Windows and shell scripts on UNIX.

Writing a screen saver is more complex than using other APIs, so I will describe this part in the second part of this series. However, if you want to start learning right away, you can download the SDK (https://jdic.dev.java.net/documentation/incubator/screensaver/

) And some community Screen Saver programs

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.