- 浏览: 233991 次
- 性别:
- 来自: 深圳
-
文章分类
最新评论
-
JENNY_JOKER:
服务端没有问题 客户端的运行的时候报实例化异常 不能实例化我的 ...
CXF和spring整合实现webservice实例 -
ytqtxf:
在哪里可以下载demo ?
CXF和spring整合实现webservice实例 -
zhang_shuai870717:
谢谢!成功。
CXF和spring整合实现webservice实例 -
xizhenyin:
你好 大神,问下 onUpload$browse(Upload ...
ZK实现上传设置文件编码 -
greatzerg:
楼主,我用楼主写的实例运行时,在tomcat启动时就报异常了 ...
CXF和spring整合实现webservice实例
Running the DesktopDemo Application
DesktopDemo is a simple Java application that uses the new Desktop API. The application has one main window that exposes the entire API, allowing you to do three things:
1. Launch the default browser with a specific URI.
2. Launch the default email client with a mail recipient.
3. Launch an associated application to open, edit, or print a file.
You can run this application by downloading the application source and JAR files, changing your console's active directory to the application project's dist directory, and executing the following command using a JDK 6:
Determining Desktop API Support
Before launching the browser, email client, or any application, DesktopDemo must determine whether your platform supports the API. First, however, DesktopDemo disables all the graphical text fields and buttons. It enables these graphical components after determining that the platform supports them.
After instantiating the UI, the application's constructor quickly disables the few components of this application as shown in the following code:
Use the Desktop.isDesktopSupported() method to determine whether the Desktop API is available. On the Solaris Operating System and the Linux platform, this API is dependent on Gnome libraries. If those libraries are unavailable, this method will return false. After determining that the API is supported, that is, the isDesktopSupported() returns true, the application can retrieve a Desktop instance using the static method getDesktop().
If your application doesn't check for API support using isDesktopSupported() before calling getDesktop(), it must be prepared to catch an UnsupportedOperationException, which is thrown when your application requests a Desktop instance on a platform that does not support these features. Additionally, if your application runs in an environment without a keyboard, mouse, or monitor (a "headless" environment), the getDesktop() method will throw a java.awt.HeadlessException.
Once retrieved, the Desktop instance allows your application to browse, mail, open, edit, or even print a file or URI, but only if the retrieved Desktop instance supports these activities. Each of these activities is called an action, and each is represented as a Desktop.Action enumeration instance:
* BROWSE. Represents a browse action performed by the host's default browser
* MAIL. Represents a mail action performed by the host's default email client
* OPEN. Represents an open action performed by an application associated with opening a specific file type
* EDIT. Represents an edit action performed by an application associated with editing a specific file type
* PRINT. Represents a print action performed by an application associated with printing a specific file type
Opening the Browser
Calling the following instance method will open your host's default browser:
Because DesktopDemo's UI components are enabled only if the associated Desktop.Action is supported, this simple demo application doesn't need to check support again before actually calling the browse() method. However, checking action support before each invocation may be more robust in real-world applications:
DesktopDemo adds a java.awt.event.ActionListener to each button. When enabled, the Launch Browser button invokes the following method through its ActionListener:
The browse() method can throw a variety of exceptions, including a NullPointerException if the URI is null, an UnsupportedOperationException if the BROWSE action is unsupported, an IOException if the default browser or application can't be found or launched, and a SecurityException if a security manager denies the invocation.
If all goes well, however, the listener retrieves the text from the associated text field in Figure 4, creates a URI, and invokes the browse() method. The code above launches the default browser on your system and instructs the browser to load the URI, as Figure 5 shows.
Sending Email
Applications can launch the host's default email client, if that action is supported, by calling this Desktop instance method:
DesktopDemo has an ActionListener for the Launch Mail button. In this case, the listener invokes the following method:
The onLaunchMail() method retrieves the email recipient from the associated text field, creates the URI with a mailto scheme argument if a recipient exists, and then invokes the mail() method. The mail() method is overloaded, so you can call it with or without a URI that represents its mailto recipient.
You can use more than just a single email recipient when creating this URI. The mailto scheme supports CC, BCC, SUBJECT, and BODY fields as well. For example, the following text could be used to create a mailto URI:
You can, of course, invoke mail() without an argument. In this case, your email client will launch a new email window without specifying a recipient, subject, or body message.
Opening, Editing, and Printing a File
Java applications can open, edit, and print files from their associated application using a Desktop object's open(), edit(), and print() methods, respectively (see Figure
. Again, DesktopDemo allows these actions only if the Desktop instance supports them, so in this application scenario, it is not necessary to check for support again.
Each of DesktopDemo's radio buttons has its own ActionListener as well. In this case, each sets an instance variable so that it represents the most recently selected button's associated Desktop.Action:
Desktop.Action action;
When you press the Launch Default Application button, it invokes its own listener, which calls the following method:
This method determines which Desktop.Action is selected and invokes the appropriate Desktop instance method, either open(), edit(), or print(). Each method requires a File argument, which will be used to perform the requested action.
Interestingly, different applications may be registered for these different actions even on the same file type. For example, the Firefox browser may be launched for the OPEN action, Emacs for the EDIT action, and yet a different application for the PRINT action. Your host desktop's associations are used to determine what application should be invoked. The ability to manipulate desktop file associations is not possible with the existing Desktop API in JDK 6, and those associations can be created or changed only with platform-dependent tools at this time.
Summary
-----------------
Desktop integration is an important theme. One way that Java SE 6 technology supports this theme is through the java.awt.Desktop API. This API allows Java applications to launch the host's default browser and email client. Additionally, Java applications can launch applications associated with specific file types to open, edit, and print files. Although Java applications cannot manipulate, create, or change file associations, the Desktop API does allow Java applications to launch the default associated applications. This article provides a sample application that demonstrates the API, which you can download from this site.
Note: Any API additions or other enhancements to the Java SE platform specification are subject to review and approval by the JSR 270 Expert Group.
For More Information
DesktopDemo is a simple Java application that uses the new Desktop API. The application has one main window that exposes the entire API, allowing you to do three things:
1. Launch the default browser with a specific URI.
2. Launch the default email client with a mail recipient.
3. Launch an associated application to open, edit, or print a file.

You can run this application by downloading the application source and JAR files, changing your console's active directory to the application project's dist directory, and executing the following command using a JDK 6:
java -jar DesktopDemo.jar
Determining Desktop API Support
Before launching the browser, email client, or any application, DesktopDemo must determine whether your platform supports the API. First, however, DesktopDemo disables all the graphical text fields and buttons. It enables these graphical components after determining that the platform supports them.
After instantiating the UI, the application's constructor quickly disables the few components of this application as shown in the following code:
public DesktopDemo() { // Initiate all GUI components. initComponents(); // Disable buttons that launch browser and email client. // Disable buttons that open, edit, and print files. disableActions(); ... } /** * Disable all graphical components until we know * whether their functionality is supported. */ private void disableActions() { txtBrowserURI.setEnabled(false); btnLaunchBrowser.setEnabled(false); txtMailTo.setEnabled(false); btnLaunchEmail.setEnabled(false); rbEdit.setEnabled(false); rbOpen.setEnabled(false); rbPrint.setEnabled(false); txtFile.setEnabled(false); btnLaunchApplication.setEnabled(false); } ... public javax.swing.JTextField txtBrowserURI; public javax.swing.JButton btnLaunchBrowser; public javax.swing.JTextField txtMailTo; public javax.swing.JButton btnLaunchEmail; public javax.swing.JRadioButton rbEdit; public javax.swing.JRadioButton rbOpen; public javax.swing.JRadioButton rbPrint; public javax.swing.JTextField txtFile; public javax.swing.JButton btnLaunchApplication;
Use the Desktop.isDesktopSupported() method to determine whether the Desktop API is available. On the Solaris Operating System and the Linux platform, this API is dependent on Gnome libraries. If those libraries are unavailable, this method will return false. After determining that the API is supported, that is, the isDesktopSupported() returns true, the application can retrieve a Desktop instance using the static method getDesktop().
Desktop desktop = null; // Before more Desktop API is used, first check // whether the API is supported by this particular // virtual machine (VM) on this particular host. if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); ...
If your application doesn't check for API support using isDesktopSupported() before calling getDesktop(), it must be prepared to catch an UnsupportedOperationException, which is thrown when your application requests a Desktop instance on a platform that does not support these features. Additionally, if your application runs in an environment without a keyboard, mouse, or monitor (a "headless" environment), the getDesktop() method will throw a java.awt.HeadlessException.
Once retrieved, the Desktop instance allows your application to browse, mail, open, edit, or even print a file or URI, but only if the retrieved Desktop instance supports these activities. Each of these activities is called an action, and each is represented as a Desktop.Action enumeration instance:
* BROWSE. Represents a browse action performed by the host's default browser
* MAIL. Represents a mail action performed by the host's default email client
* OPEN. Represents an open action performed by an application associated with opening a specific file type
* EDIT. Represents an edit action performed by an application associated with editing a specific file type
* PRINT. Represents a print action performed by an application associated with printing a specific file type
Opening the Browser
Calling the following instance method will open your host's default browser:
public void browse(URI uri) throws IOException
Because DesktopDemo's UI components are enabled only if the associated Desktop.Action is supported, this simple demo application doesn't need to check support again before actually calling the browse() method. However, checking action support before each invocation may be more robust in real-world applications:
if (desktop.isSupported(Desktop.Action.BROWSE)) { // launch browser ... }
DesktopDemo adds a java.awt.event.ActionListener to each button. When enabled, the Launch Browser button invokes the following method through its ActionListener:
private void onLaunchBrowser(java.awt.event.ActionEvent evt) { URI uri = null; try { uri = new URI(txtBrowserURI.getText()); desktop.browse(uri); } catch(IOException ioe) { ioe.printStackTrace(); } catch(URISyntaxException use) { use.printStackTrace(); } ... }
The browse() method can throw a variety of exceptions, including a NullPointerException if the URI is null, an UnsupportedOperationException if the BROWSE action is unsupported, an IOException if the default browser or application can't be found or launched, and a SecurityException if a security manager denies the invocation.
If all goes well, however, the listener retrieves the text from the associated text field in Figure 4, creates a URI, and invokes the browse() method. The code above launches the default browser on your system and instructs the browser to load the URI, as Figure 5 shows.
Sending Email
Applications can launch the host's default email client, if that action is supported, by calling this Desktop instance method:
public void mail(URI uri) throws IOException
DesktopDemo has an ActionListener for the Launch Mail button. In this case, the listener invokes the following method:
private void onLaunchMail(java.awt.event.ActionEvent evt) { String mailTo = txtMailTo.getText(); URI uriMailTo = null; try { if (mailTo.length() > 0) { uriMailTo = new URI("mailto", mailTo, null); desktop.mail(uriMailTo); } else { desktop.mail(); } } catch(IOException ioe) { ioe.printStackTrace(); } catch(URISyntaxException use) { use.printStackTrace(); } ... }
The onLaunchMail() method retrieves the email recipient from the associated text field, creates the URI with a mailto scheme argument if a recipient exists, and then invokes the mail() method. The mail() method is overloaded, so you can call it with or without a URI that represents its mailto recipient.
You can use more than just a single email recipient when creating this URI. The mailto scheme supports CC, BCC, SUBJECT, and BODY fields as well. For example, the following text could be used to create a mailto URI:
mailto:duke@sun.com?SUBJECT=Happy New Year!&BODY=Happy New Year, Duke!

You can, of course, invoke mail() without an argument. In this case, your email client will launch a new email window without specifying a recipient, subject, or body message.
Opening, Editing, and Printing a File
Java applications can open, edit, and print files from their associated application using a Desktop object's open(), edit(), and print() methods, respectively (see Figure

Each of DesktopDemo's radio buttons has its own ActionListener as well. In this case, each sets an instance variable so that it represents the most recently selected button's associated Desktop.Action:
Desktop.Action action;
private void onPrintAction(java.awt.event.ActionEvent evt) { action = Desktop.Action.PRINT; } private void onEditAction(java.awt.event.ActionEvent evt) { action = Desktop.Action.EDIT; } private void onOpenAction(java.awt.event.ActionEvent evt) { action = Desktop.Action.OPEN; }
When you press the Launch Default Application button, it invokes its own listener, which calls the following method:
private void onLaunchDefaultApplication(java.awt.event.ActionEvent evt) { String fileName = txtFile.getText(); File file = new File(fileName); try { switch(action) { case OPEN: desktop.open(file); break; case EDIT: desktop.edit(file); break; case PRINT: desktop.print(file); break; } } catch (IOException ioe) { ioe.printStackTrace(); } ... }
This method determines which Desktop.Action is selected and invokes the appropriate Desktop instance method, either open(), edit(), or print(). Each method requires a File argument, which will be used to perform the requested action.
Interestingly, different applications may be registered for these different actions even on the same file type. For example, the Firefox browser may be launched for the OPEN action, Emacs for the EDIT action, and yet a different application for the PRINT action. Your host desktop's associations are used to determine what application should be invoked. The ability to manipulate desktop file associations is not possible with the existing Desktop API in JDK 6, and those associations can be created or changed only with platform-dependent tools at this time.
Summary
-----------------
Desktop integration is an important theme. One way that Java SE 6 technology supports this theme is through the java.awt.Desktop API. This API allows Java applications to launch the host's default browser and email client. Additionally, Java applications can launch applications associated with specific file types to open, edit, and print files. Although Java applications cannot manipulate, create, or change file associations, the Desktop API does allow Java applications to launch the default associated applications. This article provides a sample application that demonstrates the API, which you can download from this site.
Note: Any API additions or other enhancements to the Java SE platform specification are subject to review and approval by the JSR 270 Expert Group.
For More Information
发表评论
-
jdom删除节点报JAVA.UTIL.CONCURRENTMODIFICATIONEXCEPTION
2011-12-19 14:10 1890jdom删除节点时报异常:JAVA.UTIL.CONCURRE ... -
捕获删除包含外键的数据异常(转载)
2011-12-01 11:20 6967所谓字典就是数据库应用中被其他表(通常加以外键约束)引用 ... -
file.delete()不能删除的原因(转载)
2011-11-22 19:57 7516file.delete()不能删除的原因: 搞定了,终 ... -
Java用native2ascii命令做unicode编码转换(转载)
2011-11-16 14:35 1305背景:在做Java开发的时候,常常会出现一些乱码,或者无法 ... -
(转)ANSI编码和Unicode编码的不同-chaijunkun-CSDN
2011-09-15 10:57 4379ANSI编码最常见的应用就是在Windows当中的记事本程序中 ... -
Java Date一个小bug
2011-08-26 10:46 2225public static void main(String[ ... -
Java 调用 Shell 命令(转载)
2011-07-12 11:40 2986近日项目中有这样一个需求:系统中的外币资金调度完成以后 ... -
(转)ThreadPoolExecutor的执行顺序
2011-04-07 09:51 2155ThreadPoolExecutor类关于排队是这样描述的: ... -
MD5 Java应用
2011-02-23 17:52 1491import java.security.MessageD ... -
Axis简介
2010-11-22 10:34 1615Apache SOAP是SOAP首个 ... -
O'Reilly出版的一些经典Java书籍
2010-10-15 11:36 1393O'Reilly出版的一些经典Java书籍,有需要的可以参考: ... -
优化MyEclipse的启动速度和运行效率
2010-09-14 10:09 1186今天介绍几个优化MyEclipse的方法 1. 加大JVM的 ... -
设置Eclipse的内存参数
2010-09-13 17:47 8342Eclipse的插件越来越多,容量越来越大,占用空间也越来越大 ... -
windowBuilder Pro下载
2010-09-07 14:55 1981For Eclipse 3.4- http://down.g ... -
RMI plugin for eclipse
2010-09-03 16:13 1076Keygen_RMI.Plugin.v2.0.2 目前也支持v ... -
常用正则表达式
2010-07-30 13:00 93530分钟教程http://www.unibetter.com/ ... -
原码、反码、补码
2010-07-27 14:08 1226我们也已经知道如何将一个10进制数如何转换为二进制数。 但是 ... -
Java中的堆和栈
2010-07-16 14:20 1001栈与堆都是Java用来在RAM中存放数据的 ... -
java面试解惑系列
2010-07-13 14:22 818摘自藏圩人 -
java环境变量设置
2010-06-08 09:47 1265windows xp下配置JDK环境变量: 1.在“系统变量 ...
相关推荐
The Java Development Kit (JDK) APIs are specific to the JDK and will not necessarily be available in all implementations of the Java SE Platform. These APIs are in modules whose names start with jdk....
<br>splash screens, JavaScript scripting as well as the desktop and system <br>tray interfaces. <br>Unique coverage of Java game development using both the Java 3D API <br>and Java for...
Install the JSDK, information for the installation process can be found in the JSK SE home; Install the JMF, information for the installation process can be found in the JMF home; Let's call JMF...
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
前端分析-2023071100789
基于kinect的3D人体建模C++完整代码.cpp
搞机工具箱10.1.0.7z
GRU+informer时间序列预测(Python完整源码和数据),python代码,pytorch架构,适合各种时间序列直接预测。 适合小白,注释清楚,都能看懂。功能如下: 代码基于数据集划分为训练集测试集。 1.多变量输入,单变量输出/可改多输出 2.多时间步预测,单时间步预测 3.评价指标:R方 RMSE MAE MAPE,对比图 4.数据从excel/csv文件中读取,直接替换即可。 5.结果保存到文本中,可以后续处理。 代码带数据,注释清晰,直接一键运行即可,适合新手小白。
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
基于ANSYS LSDyna的DEM-SPH-FEM耦合模拟滑坡入水动态行为研究,基于ANSYS LSDyna的DEM-SPH-FEM耦合的滑坡入水模拟分析研究,基于ansys lsdyna的滑坡入水模拟dem-sph-fem耦合 ,基于ANSYS LSDyna; 滑坡入水模拟; DEM-SPH-FEM 耦合,基于DEM-SPH-FEM耦合的ANSYS LSDyna滑坡入水模拟
auto_gptq-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
复件 复件 建设工程可行性研究合同[示范文本].doc
13考试真题最近的t64.txt
好用我已经解决报错问题
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!
auto_gptq-0.4.2-cp38-cp38-win_amd64.whl
自动立体库设计方案.pptx
# 踏入C语言的奇妙编程世界 在编程的广阔宇宙中,C语言宛如一颗璀璨恒星,以其独特魅力与强大功能,始终占据着不可替代的地位。无论你是编程小白,还是有一定基础想进一步提升的开发者,C语言都值得深入探索。 C语言的高效性与可移植性令人瞩目。它能直接操控硬件,执行速度快,是系统软件、嵌入式开发的首选。同时,代码可在不同操作系统和硬件平台间轻松移植,极大节省开发成本。 学习C语言,能让你深入理解计算机底层原理,培养逻辑思维和问题解决能力。掌握C语言后,再学习其他编程语言也会事半功倍。 现在,让我们一起开启C语言学习之旅。这里有丰富教程、实用案例、详细代码解析,助你逐步掌握C语言核心知识和编程技巧。别再犹豫,加入我们,在C语言的海洋中尽情遨游,挖掘无限可能,为未来的编程之路打下坚实基础!
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!
在日常的工作和学习中,你是否常常为处理复杂的数据、生成高质量的文本或者进行精准的图像识别而烦恼?DeepSeek 或许就是你一直在寻找的解决方案!它以其高效、智能的特点,在各个行业都展现出了巨大的应用价值。然而,想要充分发挥 DeepSeek 的优势,掌握从入门到精通的知识和技能至关重要。本文将从实际应用的角度出发,为你详细介绍 DeepSeek 的基本原理、操作方法以及高级技巧。通过系统的学习,你将能够轻松地运用 DeepSeek 解决实际问题,提升工作效率和质量,让自己在职场和学术领域脱颖而出。现在,就让我们一起开启这场实用又高效的学习之旅吧!