Java SE 6 Update 10 reintroduces the concept of the applet, which unifies the desktop and browser experience.
Starting in Java SE 6 Update, the new Java Plug-in includes a draggable feature for applets. This feature allows users to bring together their browser and desktop experience.
As a Java technology developer, you can use the rich functionalities in the Java platform to create an applet and allow the user to bring your applet to the desktop. This feature increases flexibility in application deployment and takes advantage of Java Web Start technology to increase the ease of deploying Java Network Launching Protocol (JNLP) applets.
Your comments, suggestions, and other feedback on this capability are welcome. Contact the development team through the Java Plug-in forum.
The new Java Plug-in is designed to work in the following browsers:
Note that Firefox 2 uses the Classic Java Plug-in and does not provide the new draggable applet feature.
Next, download and install Java SE 6 Update 10 or later. You don't necessarily need to install the JDK. Install only the JRE to experience the new features in Java SE 6 Update 10 if you are not compiling your code.
The new Java Plug-in allows the user to drag your applet from the browser onto the desktop, with the applet continuing to run. Because the Java Plug-in uses Java Web Start technology, when the user closes the web page, you can prompt the user to decide whether to create a shortcut on the desktop. With the shortcut, the user can now directly launch your applet without opening a web browser and searching for your applet.
An applet that requires LiveConnect will lose its session when the user closes a web browser.
To take advantage of this new draggable feature in your applet, enable the draggable function within your
<APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300"> <PARAM name="draggable" value="true"> </APPLET>
In addition to the new parameter support of this draggable feature, new methods have been implemented in the Applet class. By overriding the following methods, you can configure the behavior of your applets when the drag event happens. The following are the newly implemented methods:
public boolean isAppletDragStart(MouseEvent e);
public void appletDragStarted();
public void appletDragFinished();
public void setAppletCloseListener(ActionListener l);
public void appletRestored();
If your applet supplies the method
public void appletDragStarted();, it will be called when any of these conditions arise:
JFrameis not yet visible.
This gives you the opportunity to change the state of decorations on the frame, use the experimental functionality in Java SE 6 Update 10 to make the frame translucent (useful when building shaped widgets), and perform other operations.
If your applet supplies the method
public void appletDragFinished();, it will be called once the applet has been dropped onto the desktop.
By default, a small floating Close button will be drawn above and to the right of the applet's region, and this will track the applet as it moves around the screen. You can customize this user interface.
If your applet defines the method
public void setAppletCloseListener(ActionListener l);, then it is assumed that your applet will draw its own Close button inside its region. In this case, you should save the
ActionListener object passed in to this method call when it is made by the Java Plug-in, and call its
actionPerformed method to initiate the shutdown of the applet in response to the user's input. The
ActionEvent argument to the
actionPerformed method may be null. It is ignored.
If the user clicks the Close button while the web page that originally contained the applet is still visible, then the applet will be placed back into its original location on the page, and the method
public void appletRestored(); will be called. If the applet has been disconnected from the browser, as this article will soon demonstrate, then normal applet shutdown will be initiated: The
destroy methods will be called.
Other browser services, such as the implementation of
AppletContext.showDocument(), are replaced with alternate implementations that have slightly less fine-grained control, specifically the following:
Any calls to
AppletContext.showDocument will open a new browser window. If a call is made to
showDocument(URL url, String target), the target will be ignored.
AppletContext.showStatus will display the string in the Java Console, if it is open, rather than in the browser's status bar.
Queries of proxy settings and cookies, which are normally redirected back to the web browser, are instead handled by the platform-specific settings. For example, on a Microsoft Windows platform, the proxy settings for Internet Explorer are implicitly the system wide proxy settings, and these will be used for a disconnected applet even if Mozilla Firefox was originally used to launch the applet.
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. Try this with the following clock-sample applet. You must have Java SE 6 Update 10 or later, and either Mozilla Firefox 3 or Internet Explorer 6 or 7 in order to use this feature.
For source code, refer to the clock sample delivered with the Java SDK.
The following JNLP applet uses a JNLP file to specify the application attributes and shortcuts that will be created on the user's desktop. When the user presses the Alt key and the left mouse button to drag the applet out of the browser, then closes the browser, a pop-up dialog box asks the user to decide whether to create a shortcut on the desktop. This feature greatly enhances the flexibility in deploying your applets to the end-user's desktop.
The Java SE 6 Update 10 Feed Reader demo is a simple model-view-controller (MVC) design application that uses some of the latest features provided in Java SE 6 Update 10, including the JNLP applet, the draggable applet, and the new Java system properties for Pack200. To read more about the new features, see the For More Information section at the end of this article.
The feed-reader demo retrieves feeds from several Sun blogs every 10 minutes and provides you with the latest Java SE 6 Update 10 early access news. It provides entries from SDN Program News, the Aquarium (GlassFish), and Oracle employee blogs.
In addition to the new features in Java SE 6 Update 10, this demo uses the Desktop API, which is new in Java SE 6. Make sure that you have installed the latest Java SE 6 build.
Java SE 6 Update 10 is an update release with new features that target the consumer end-user experience. These new features include Java Kernel, Java Quick Starter, Java Deployment Toolkit, Next Generation Java Plug-in, Nimbus Look and Feel, and new 3D acceleration support. For a list of the new features, see the Java SE 6 Update 10 Release Notes.
To try these new features, download the latest Java SE 6 Update 10.
For a high-level overview of the new features, see Ethan Nicholas's article, Introducing Java SE 6 Update 10.
For detailed information about the new Java Plug-in and this feature, see the release notes.