The New Draggable Applet Feature in the Java SE 6
By Roger Yeung, July 2008
Articles Index
Java SE Update 10, currently in beta release. Java SE 6 Update 10 reintroduces the concept of the applet, which unifies the desktop and browser experience.
Contents
Introduction
What You Need
The New Draggable Applet Feature
Two Demo Applets
About the Java SE 6 Update 10 Feed Reader
What's Next?
For More Information
About the Author
Introduction
Starting in Java SE 6 Update 10, currently in beta release, 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.
What You Need
The new Java Plug-in is designed to work in the following browsers:
Internet Explorer 6 and 7 on Windows XP and Vista
Firefox 3 on Windows XP, Windows Vista, Solaris, and Linux
Note that Firefox 2 uses the Classic Java Plug-in and does not provide the new draggable applet feature.
Next, download and install the latest Java SE 6 Update 10 beta build. 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 Draggable Applet Feature
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 tags:
<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:
The applet has been removed from its original parent.
It has been placed into the new undecorated top-level Frame or JFrame.
The new Frame or JFrame is 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 stop and destroy methods will be called.
If the user drags an applet out of the web page, then navigates away from that web page or shuts down the web browser, the applet is conceptually disconnected from the web browser. This means that certain services, such as Java and JavaScript communication, are disabled.
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 attempt to call from Java to JavaScript through the netscape.javascript.JSObject class will result in a JSException.
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.
Calls to 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 systemwide proxy settings, and these will be used for a disconnected applet even if Mozilla Firefox was originally used to launch the applet.
Two Demo Applets
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 the latest Java SE 6 Update 10 beta build, 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.
Check out this video, in which Ken Russell demonstrated this feature at the 2008 JavaOne conference (about 58 minutes).
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.
Here are the JNLP file and the source code for this applet.
About the Java SE 6 Update 10 Feed Reader
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 Sun 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.
What's Next?
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 Early Access Program and the Testing Guidelines.
To try these new features, download the latest Java SE 6 Update 10 build and send your feedback to the development team.
For a high-level overview of the new features, see Ethan Nicholas's article, Introducing Java SE 6 Update 10 Beta.
For detailed information about the new Java Plug-in and this feature, see the release notes.
For More Information
Java SE 6 Update 10
Java SE 6 Update 10 Features Testing Guidelines
Next-Generation Plug-in Release Notes
New Java System Properties
About the Author
Roger Yeung is a software engineer in the Java SE platform at Sun Microsystems. His interests include security as well as Java Web Start, Sun SPOT, and GIS technologies.
Articles Index
Java SE Update 10, currently in beta release. Java SE 6 Update 10 reintroduces the concept of the applet, which unifies the desktop and browser experience.
Contents
Introduction
What You Need
The New Draggable Applet Feature
Two Demo Applets
About the Java SE 6 Update 10 Feed Reader
What's Next?
For More Information
About the Author
Introduction
Starting in Java SE 6 Update 10, currently in beta release, 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.
What You Need
The new Java Plug-in is designed to work in the following browsers:
Internet Explorer 6 and 7 on Windows XP and Vista
Firefox 3 on Windows XP, Windows Vista, Solaris, and Linux
Note that Firefox 2 uses the Classic Java Plug-in and does not provide the new draggable applet feature.
Next, download and install the latest Java SE 6 Update 10 beta build. 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 Draggable Applet Feature
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 tags:
<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:
The applet has been removed from its original parent.
It has been placed into the new undecorated top-level Frame or JFrame.
The new Frame or JFrame is 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 stop and destroy methods will be called.
If the user drags an applet out of the web page, then navigates away from that web page or shuts down the web browser, the applet is conceptually disconnected from the web browser. This means that certain services, such as Java and JavaScript communication, are disabled.
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 attempt to call from Java to JavaScript through the netscape.javascript.JSObject class will result in a JSException.
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.
Calls to 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 systemwide proxy settings, and these will be used for a disconnected applet even if Mozilla Firefox was originally used to launch the applet.
Two Demo Applets
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 the latest Java SE 6 Update 10 beta build, 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.
Check out this video, in which Ken Russell demonstrated this feature at the 2008 JavaOne conference (about 58 minutes).
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.
Here are the JNLP file and the source code for this applet.
About the Java SE 6 Update 10 Feed Reader
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 Sun 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.
What's Next?
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 Early Access Program and the Testing Guidelines.
To try these new features, download the latest Java SE 6 Update 10 build and send your feedback to the development team.
For a high-level overview of the new features, see Ethan Nicholas's article, Introducing Java SE 6 Update 10 Beta.
For detailed information about the new Java Plug-in and this feature, see the release notes.
For More Information
Java SE 6 Update 10
Java SE 6 Update 10 Features Testing Guidelines
Next-Generation Plug-in Release Notes
New Java System Properties
About the Author
Roger Yeung is a software engineer in the Java SE platform at Sun Microsystems. His interests include security as well as Java Web Start, Sun SPOT, and GIS technologies.
相关推荐
Java Virtual Machine Support for Non-Java Languages: Java SE 7 introduces a new JVM instruction that simplifies the implementation of dynamically typed programming languages on the JVM. Garbage-First...
JQuery的插件,实现拖拽效果所需要的插件,jquery.ui.draggable.js
《React Draggable 源码解析》 React Draggable 是一个流行的开源库,它为React应用提供了可拖动组件的功能。这个"react-draggable-master.zip"文件包含了该库的源代码,对于开发者来说,深入理解其内部工作原理是...
其中,jQuery UI是jQuery的一个扩展,它提供了丰富的用户界面组件,包括我们今天要讨论的"Draggable"功能。这个功能允许用户通过鼠标拖动元素在页面上自由移动,极大地提升了网页的交互性。 `jQuery UI Draggable` ...
Classes, closures, persistence, Flash, and JavaScript embedded in Java applications Part I explains the core JavaScript language in detail. If you are new to JavaScript, it will teach you the ...
Draggable为基于Sortable.js的vue组件,用以实现拖拽功能。 具体说明,请参考:学习链接 npm官方演示: vuedraggable特性: 支持触摸设备 支持拖拽和选择文本 支持智能滚动 支持不同列表之间的拖拽 不以jQuery...
《draggable.js源码分析——探索JavaScript拖拽功能实现》 在前端开发中,实现元素的拖放(Drag and Drop)功能是一项常见的需求。KISSY编辑器中的draggable.js模块,就是一个轻量级的解决方案,它使得在网页上创建...
6. **获取和设置选项**:可以使用`.draggable('option', 'optionName')`来获取选项值,如`var addClasses = $('#draggable').draggable('option', 'addClasses');`,并使用`.draggable('option', 'optionName', ...
### Jquery UI Draggable中文API及使用 #### 概述 Jquery UI 是一套基于 jQuery 的用户界面组件库,提供了一系列可复用的交互式组件,简化了网页开发者的工作量。其中,Draggable 组件是一种非常实用的功能,它...
Vue.Draggable是一款在Vue.js生态中广泛使用的第三方库,它允许开发者轻松地实现元素的拖放功能。这款插件是基于Sortable.js构建的,它为Vue提供了强大的拖放和重新排序的能力,使得用户界面更加交互性和动态。在这...
本文实例为大家分享了vue插件draggable实现拖拽移动图片顺序的具体方法,供大家参考,具体内容如下 例如图片显示的这种图片列表、商品展示需要拖动图片改变顺序,vuedraggable可以实现拖拽。 首先, npm i ...
Draggable 拖拽控件 DragTarget 接收Draggable的控件
在本文中,我们将深入探讨jQuery UI中的`draggable`功能,以及如何利用它来实现一个交互式的用户界面。`draggable`是jQuery UI库中的一个关键组件,它允许用户通过鼠标拖动DOM元素,从而创建出各种动态效果,如拖放...
2. **初始化元素**:通过JavaScript选择需要拖放的元素,并调用`draggable()`方法初始化,例如:`document.getElementById('myElement').draggable();` 3. **设置选项**:可以传入对象作为参数,自定义拖放行为,如...
1.npm install draggable-vue-directive --save 2.<div v-draggable> classic draggable 3. import { Draggable } from 'draggable-vue-directive' ... export default { directives: { Draggable, }, ... 4...
这个“前端项目-draggable.zip”文件包含了一个JavaScript库,用于实现这样的功能。这个库被称为"你祖父母警告过你的javascript拖放库",可能是开发者以幽默的方式表达了其易于理解和使用,就像祖父母讲述的故事那样...
Please use the , vue-draggable-nested-tree will no longer be maintained. 请使用新发布的, vue-draggable-nested-tree 将不再维护. Please use the , vue-draggable-nested-tree will no longer be maintained. ...
一个资源js,highcharts的一个插件。加上后,可以设置图例,使图例可拖动 legend下面设置 floating: true, draggable: true, 如果没有这个js引入,则设置不生效,不能拖动
JS draggable location waterfall flow layout code is a grid waterfall flow layout style, supporting image dragging position and size change effects
"draggable"特性是jQuery库的一个插件,它使得开发者能够轻松地为页面上的元素添加拖拽功能,从而实现更丰富的用户体验。在本篇文章中,我们将深入探讨如何使用draggable插件以及与之相关的知识点。 首先,我们需要...