Example usage for java.awt Desktop isDesktopSupported

List of usage examples for java.awt Desktop isDesktopSupported

Introduction

In this page you can find the example usage for java.awt Desktop isDesktopSupported.

Prototype

public static boolean isDesktopSupported() 

Source Link

Document

Tests whether this class is supported on the current platform.

Usage

From source file:Main.java

public static void main(String[] a) throws Exception {
    Desktop desktop = null;/*from  ww w . ja v  a2s . c om*/
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
    }

    desktop.mail();
}

From source file:Test.java

public static void main(String[] a) throws Exception {
    Desktop desktop = null;//from   www  . j a va  2 s . c  o  m
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
    }

    desktop.mail("mailto", "a@a.net", null);
}

From source file:Main.java

public static void main(String[] a) {
    try {// www.j a  v  a2s. c  o m
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.edit(new File("c:\\a.txt"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] a) {
    try {/* ww w .j  a v a 2 s.c  o  m*/
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.open(new File("c:\\a.doc"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] a) {
    try {//from  ww w.j ava 2s.  c o  m
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.print(new File("c:\\a.txt"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Test.java

public static void main(String[] a) {
    try {//w w  w  .j a v a  2 s .  com
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.open(new File("c:\\a.txt"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] a) throws URISyntaxException {
    try {// ww  w  . j a  v  a 2s.  c  o  m
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        desktop.mail(new URI("name@address.net"));
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] a) {
    try {// w  w  w  .  j  av  a 2 s  .  c  o m
        URI uri = new URI("http://www.java2s.com");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
        }

        if (desktop != null)
            desktop.browse(uri);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException use) {
        use.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] a) {
    try {/*  w ww.ja v  a 2s . c  o  m*/
        URI uri = new URI("http://www.java2s.com");
        Desktop desktop = null;
        if (Desktop.isDesktopSupported()) {
            desktop = Desktop.getDesktop();
            desktop.isSupported(Desktop.Action.PRINT);
        }

        if (desktop != null)
            desktop.browse(uri);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException use) {
        use.printStackTrace();
    }

}

From source file:DesktopDemo.java

public static void main(String[] args) {

    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
    } else {/*from   www .j a v  a2s.  c  o  m*/
        System.out.println("Desktop class is not supported");
        System.exit(1);
    }
    JMenuItem openItem = new JMenuItem("Open");
    JMenuItem editItem = new JMenuItem("Edit");
    JMenuItem printItem = new JMenuItem("Print");
    JMenuItem browseToItem = new JMenuItem("Go to www.java2s.com");
    JMenuItem mailToItem = new JMenuItem("Email to a@java.com");
    JMenu fileMenu = new JMenu("File");
    JMenu mailMenu = new JMenu("Email");
    JMenu browseMenu = new JMenu("Browser");

    openItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                try {
                    desktop.open(chooser.getSelectedFile().getAbsoluteFile());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    fileMenu.add(openItem);

    editItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                try {
                    desktop.edit(chooser.getSelectedFile().getAbsoluteFile());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    fileMenu.add(editItem);

    printItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                try {
                    desktop.print(chooser.getSelectedFile().getAbsoluteFile());
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    fileMenu.add(printItem);

    browseToItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                URI browseURI = new URI("www.java2s.com");
                desktop.browse(browseURI);
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
        }
    });
    browseMenu.add(browseToItem);

    mailToItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                URI mailURI = new URI("mailto:support@java.com");
                desktop.mail(mailURI);
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
        }
    });
    mailMenu.add(mailToItem);

    JMenuBar jMenuBar = new JMenuBar();
    jMenuBar.add(fileMenu);
    jMenuBar.add(browseMenu);
    jMenuBar.add(mailMenu);

    JFrame frame = new JFrame();
    frame.setTitle("Desktop Helper Applications");
    frame.setSize(300, 100);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(jMenuBar);
    frame.setVisible(true);

}