Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > Java > 学习Java6(七)Desktop(6)打印所选文件
【标  题】:学习Java6(七)Desktop(6)打印所选文件
【关键字】:Java6,Desktop
【来  源】:http://www.blogjava.net/vip01/archive/2007/01/25/95953.html

学习Java6(七)Desktop(6)打印所选文件

Your Ad Here

?

?1?import?java.awt.Desktop;
?2?import?java.awt.event.ActionEvent;
?3?import?java.awt.event.ActionListener;
?4?import?java.io.File;
?5?import?java.io.IOException;
?6?import?javax.swing.JButton;
?7?import?javax.swing.JFileChooser;
?8?import?javax.swing.JFrame;
?9?import?javax.swing.UIManager;
10?
11?public?class?TestDesktopPrintFile?{
12?????private?JFrame?frame;
13?
14?????/**
15??????*?Launch?the?application
16??????*?
17??????*?@param?args
18??????*/
19?????public?static?void?main(String?args[])?{
20?????????try?{
21?????????????TestDesktopPrintFile?window?=?new?TestDesktopPrintFile();
22?????????????window.frame.setVisible(true);
23?????????}?catch?(Exception?e)?{
24?????????????e.printStackTrace();
25?????????}
26?????}
27?
28?????/**
29??????*?Create?the?application
30??????*/
31?????public?TestDesktopPrintFile()?{
32?????????initialize();
33?????}
34?
35?????/**
36??????*?Initialize?the?contents?of?the?frame
37??????*/
38?????private?void?initialize()?{
39?????????try?{
40?????????????UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
41?????????}?catch?(Exception?ex)?{
42?????????????ex.printStackTrace();
43?????????}
44?????????frame?=?new?JFrame();
45?????????frame.getContentPane().setLayout(null);
46?????????frame.setBounds(100,?100,?225,?86);
47?????????frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
48?????????final?JButton?openButton?=?new?JButton();
49?????????openButton.setBounds(53,?10,?106,?31);
50?????????openButton.addActionListener(new?ActionListener()?{
51?????????????public?void?actionPerformed(ActionEvent?e)?{
52?????????????????if?(Desktop.isDesktopSupported())?{
53?????????????????????Desktop?desktop?=?Desktop.getDesktop();
54?????????????????????JFileChooser?jfc?=?new?JFileChooser();
55?????????????????????jfc.showOpenDialog(frame);
56?????????????????????File?file?=?jfc.getSelectedFile();
57?????????????????????if?(file?!=?null)?{
58?????????????????????????try?{
59?????????????????????????????desktop.print(file);
60?????????????????????????}?catch?(IOException?e1)?{
61?????????????????????????????e1.printStackTrace();
62?????????????????????????}
63?????????????????????}
64?????????????????}?else?{
65?????????????????????System.out.println("不支持desktop");
66?????????????????}
67?????????????}
68?????????});
69?????????openButton.setText("print");
70?????????frame.getContentPane().add(openButton);
71?????}
72?}
73?



打印之前会先打开默认编辑器。。。。。。。。。。不知道为啥不是直接打印
没打印机的人飘过
JSPWiki 插件介绍及 HelloWorld 开发:【上一篇】
HTTP请求发送XML数据:【下一篇】
【相关文章】
  • 学习Java6(一) WebServices (4)传递Object
  • 学习Java6(一) WebServices (5)传递List(失败)
  • 学习Java6(六) 嵌入式数据库Derby(8)Derby+spring+hibernate
  • 学习Java6(六) 嵌入式数据库Derby(1)简介
  • 学习Java6(六) 嵌入式数据库Derby(2)Derby在哪里?
  • 学习Java6(六) 嵌入式数据库Derby(3)一个基本的例子(建数据库、建表、插入数据、查询)
  • 学习Java6(六) 嵌入式数据库Derby(4)网络版服务端
  • 学习Java6(六) 嵌入式数据库Derby(5)网络版客户端
  • 学习Java6(六) 嵌入式数据库Derby(6)myeclipse网络方式连接Derby
  • 学习Java6(六) 嵌入式数据库Derby(7)myeclipse本地方式连接Derby
  • 【随机文章】
  • 网上“店铺”DIY(3)
  • 3.3 Authorware 编辑文本对象(2)
  • 向美国人学习“如何快乐”
  • 一个简单的linux下网络程序实例-网络编程入门
  • Do All in Cmd Shell 二
  • 实现:为自写的表格控件中的表格线 实现鼠标拖放功能
  • OS开发FAQ
  • Windows管道技术
  • Firebird简介[转载]
  • 一个检查原代码括号配对的程序,栈的应用
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.