package com.han; import java.awt.Desktop; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; /** * 桌面集成控件 * * @author HAN * */ public class Desktop_1 { private enum Action { BROWSE, EDIT, OPEN; } public Desktop_1(Action action) { // TODO Auto-generated constructor stub if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); switch (action) { case BROWSE: if (desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(new URI("www.qq.com")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; case EDIT: if (desktop.isSupported(Desktop.Action.EDIT)) { try { File file = new File("new.doc"); // File file = new File("new.txt"); if (!file.exists()) { file.createNewFile(); } desktop.edit(file); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; case OPEN: if (desktop.isSupported(Desktop.Action.OPEN)) { try { File file = new File("new.doc"); if (!file.exists()) { file.createNewFile(); } desktop.open(file); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } break; } } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub new Desktop_1(Action.BROWSE); } }