#眉標=Java #副標=Java SE 6.0系列(3) #大標=桌面(Desktop)類別 #作者=文/黃嘉輝 ============= 程式1 // 若作業系統支援Desktop類別之功能 if (Desktop.isDesktopSupported()) { // 取得Desktop物件 Desktop desktop = Desktop.getDesktop(); ... } ================ ============= 程式2 public static synchronized Desktop getDesktop(){ if (GraphicsEnvironment.isHeadless()) throw new HeadlessException(); if (!Desktop.isDesktopSupported()) { throw new UnsupportedOperationException( "Desktop API is not supported on the current platform"); } sun.awt.AppContext context = sun.awt.AppContext.getAppContext(); Desktop desktop = (Desktop)context.get(Desktop.class); if (desktop == null) { desktop = new Desktop(); context.put(Desktop.class, desktop); } return desktop; } ================ ============= 程式3 java.awt.Desktop desktop; ... // 若作業系統支援Desktop類別之功能 if (Desktop.isDesktopSupported()) { // 取得Desktop物件 desktop = Desktop.getDesktop(); } ... // 開啟檔案 desktop.open(fileName); ... // 編輯檔案 desktop.edit(fileName); ... // 列印檔案 desktop.print(fileName); ... // 執行作業系統預設之郵件工具 URI uriMailTo = new URI("mailto", mailto, null); desktop.mail(uriMailTo); ... // 以預設瀏覽器執行URI URI uri = new URI(...); desktop.browse(uri); ================ ============= [作者簡介] 黃嘉輝 U. of Wisconsin – Madison碩士畢業,現為交通大學資訊管理研究所博士後選人。曾任職於復華投信資訊部經理、聯華電子資訊部電子商務正工程師、朗訊科技CIO System Specialist等職位。在電子商務與資訊系統上,有超過十年之實務經驗,現於University of Michigan, Ann Arbor擔任研究學者。 ================