随笔 - 119  文章 - 3173  trackbacks - 0
<2007年1月>
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910

交友莫独酒,茅台西凤游。
口干古井贡,心徜洋河流。
称多情杜康,趟无量双沟。
赞中华巍巍,无此不销愁。

常用链接

留言簿(68)

随笔分类(136)

随笔档案(122)

最新随笔

搜索

  •  

积分与排名

  • 积分 - 520567
  • 排名 - 93

最新评论

 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 
10 public class TestDesktopOpenFile {
11     private JFrame frame;
12 
13     /**
14      * Launch the application
15      * 
16      * @param args
17      */
18     public static void main(String args[]) {
19         try {
20             TestDesktopOpenFile window = new TestDesktopOpenFile();
21             window.frame.setVisible(true);
22         } catch (Exception e) {
23             e.printStackTrace();
24         }
25     }
26 
27     /**
28      * Create the application
29      */
30     public TestDesktopOpenFile() {
31         initialize();
32     }
33 
34     /**
35      * Initialize the contents of the frame
36      */
37     private void initialize() {
38         frame = new JFrame();
39         frame.getContentPane().setLayout(null);
40         frame.setBounds(10010022586);
41         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
42         final JButton openButton = new JButton();
43         openButton.setBounds(531010631);
44         openButton.addActionListener(new ActionListener() {
45             public void actionPerformed(ActionEvent e) {
46                 if (Desktop.isDesktopSupported()) {
47                     Desktop desktop = Desktop.getDesktop();
48                     JFileChooser jfc = new JFileChooser();
49                     jfc.showOpenDialog(frame);
50                     File file = jfc.getSelectedFile();
51                     if (file != null) {
52                         try {
53                             desktop.open(file);
54                         } catch (IOException e1) {
55                             e1.printStackTrace();
56                         }
57                     }
58                 } else {
59                     System.out.println("不支持desktop");
60                 }
61             }
62         });
63         openButton.setText("open");
64         frame.getContentPane().add(openButton);
65     }
66 }
67 

唉,界面丑到我不忍心说了。。。。。。。。。
还是SWT好看一点
posted on 2007-01-25 15:25 交口称赞 阅读(1199) 评论(0)  编辑  收藏 所属分类: Java6

只有注册用户登录后才能发表评论。


网站导航: