maroph

Check availability of the Java Dektop API and its features

Aug 26th, 2012
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.65 KB | None | 0 0
  1. package sample;
  2.  
  3. import java.awt.Desktop;
  4. import java.awt.GraphicsEnvironment;
  5.  
  6. public class DesktopTest {
  7.     // static {
  8.     // System.setProperty("java.awt.headless" , "true");
  9.     // }
  10.     /**
  11.      * Check availability of the Dektop API and its features
  12.      *
  13.      * @param args no arguments needed
  14.      */
  15.     public static void main(String[] args) {
  16.         if (GraphicsEnvironment.isHeadless()) {
  17.             System.err.println("Application runs in headless mode");
  18.             System.exit(1);
  19.             return;
  20.         }
  21.         if (!Desktop.isDesktopSupported()) {
  22.             System.err.println("Desktop API not available");
  23.             System.exit(1);
  24.             return;
  25.         }
  26.  
  27.         Desktop desktop = Desktop.getDesktop();
  28.  
  29.         // URI sample: new URI("http://java.sun.com/");
  30.         System.out.println("desktop.browse(URI) : " +
  31.                            desktop.isSupported(Desktop.Action.BROWSE));
  32.         // URI sample:
  33.         // new URI("mailto",
  34.         //         "[email protected]?SUBJECT=Happy New Year!&BODY=Happy New Year, Duke!",
  35.         //         null);
  36.         System.out.println("desktop.mail(URI)   : " +
  37.                            desktop.isSupported(Desktop.Action.MAIL));
  38.         // File sample: new File("Test.txt");
  39.         System.out.println("desktop.open(File)  : " +
  40.                            desktop.isSupported(Desktop.Action.OPEN));
  41.         System.out.println("desktop.edit(File)  : " +
  42.                            desktop.isSupported(Desktop.Action.EDIT));
  43.         System.out.println("desktop.print(File) : " +
  44.                            desktop.isSupported(Desktop.Action.PRINT));
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment