private static void openUpWebSite(String url) { Desktop d = Desktop.getDesktop(); try { d.browse(new URI(url)); } catch (Exception e) { } }
public HyberLinkLabel(String text, String url) { this.text = text; this.url = url; try { this.isSupported = Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE); } catch (Exception e) { System.out.println("Browse is not supported"); this.isSupported = false; } setActive(false); addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent e) { setActive(isSupported); if (isSupported) setCursor(new Cursor(Cursor.HAND_CURSOR)); } public void mouseExited(MouseEvent e) { setActive(false); } public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new java.net.URI(HyberLinkLabel.this.url)); } catch (Exception ex) { System.out.println(ex.toString()); } } }); }
void lookUpTaxonID(String taxonID) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI( "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value=" + taxonID); } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
void searchName(String nameToMatch) { URI url; try { // We should look up the miITIS_TSN status, but since we don't // have any options there ... url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch); // I think the URI handles the URL encoding? } catch (URISyntaxException e) { throw new RuntimeException(e); } try { Desktop desktop = Desktop.getDesktop(); desktop.browse(url); } catch (IOException e) { MessageBox.messageBox( mainFrame, "Could not open URL '" + url + "'", "The following error occurred while looking up URL '" + url + "': " + e.getMessage(), MessageBox.ERROR); } }
public void secureUse(File fi) { // System.out.println("Using " + fi.getAbsolutePath()); try { Desktop.getDesktop().open(fi); } catch (IOException e) { e.printStackTrace(); } }
void browse(String urlStr) { try { Desktop.getDesktop().browse(new URI(urlStr)); } catch (Exception ex) { showDialog(); statusBar.setText(ex.getLocalizedMessage()); if (JConsole.isDebug()) { ex.printStackTrace(); } } }
static boolean isBrowseSupported() { return (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)); }
public void actionPerformed(ActionEvent evt) { String cmd = evt.getActionCommand(); try { if (cmd != null) { if (cmd.equalsIgnoreCase("Exit")) { System.exit(0); } if (cmd.equalsIgnoreCase("View Images")) { if (Desktop.isDesktopSupported()) { // if(Desktop.getDesktop().isSupported(Action.OPEN)) { Desktop.getDesktop().open(new File("C:/.hack3rClient/Scre")); // } } } if (cmd.equalsIgnoreCase("Toggle 10x Damage")) { newDamage = true; } if (cmd.equalsIgnoreCase("Untoggle 10x Damage")) { newDamage = false; } if (cmd.equalsIgnoreCase("Website")) { openUpWebSite("http://vestigex.com"); } if (cmd.equalsIgnoreCase("Forums")) { openUpWebSite("http://vestigex.com/forums/forum.php"); } if (cmd.equalsIgnoreCase("Vote")) { openUpWebSite("http://vestigex.com/vote.php"); } if (cmd.equalsIgnoreCase("Donate")) { openUpWebSite("http://vestigex.com/donate.html"); } if (cmd.equalsIgnoreCase("Highscores")) { openUpWebSite("http://vestigex.com/highscores/"); } if (cmd.equalsIgnoreCase("Guides")) { openUpWebSite("http://vestigex.com/forums/forum.php"); } if (cmd.equalsIgnoreCase("Support")) { openUpWebSite("vestigex.com/forums/forum.php"); JOptionPane.showMessageDialog( this, "A link to our support center on our forums has Popped up. Please create a new thread!", "Client Support", JOptionPane.INFORMATION_MESSAGE); } if (cmd.equalsIgnoreCase("Client Information")) { JOptionPane.showMessageDialog( this, "Vestige-x is Developed By Bill. We hope you enjoy the server!", "Client Updates", JOptionPane.INFORMATION_MESSAGE); } if (cmd.equalsIgnoreCase("World Map")) { launchURL("3. WorldMap.jar"); } if (cmd.equalsIgnoreCase("Item Search")) { launchURL("1. ItemList.bat"); } if (cmd.equalsIgnoreCase("Screenshot")) { takeScreenshot(true); } } } catch (Exception e) { } }
public DesktopAppFrame() { setLayout(new GridBagLayout()); final JFileChooser chooser = new JFileChooser(); JButton fileChooserButton = new JButton("..."); final JTextField fileField = new JTextField(20); fileField.setEditable(false); JButton openButton = new JButton("Open"); JButton editButton = new JButton("Edit"); JButton printButton = new JButton("Print"); final JTextField browseField = new JTextField(); JButton browseButton = new JButton("Browse"); final JTextField toField = new JTextField(); final JTextField subjectField = new JTextField(); JButton mailButton = new JButton("Mail"); openButton.setEnabled(false); editButton.setEnabled(false); printButton.setEnabled(false); browseButton.setEnabled(false); mailButton.setEnabled(false); if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.OPEN)) openButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.EDIT)) editButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.PRINT)) printButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.BROWSE)) browseButton.setEnabled(true); if (desktop.isSupported(Desktop.Action.MAIL)) mailButton.setEnabled(true); } fileChooserButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION) fileField.setText(chooser.getSelectedFile().getAbsolutePath()); } }); openButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); editButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().edit(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); printButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().print(chooser.getSelectedFile()); } catch (IOException ex) { ex.printStackTrace(); } } }); browseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(new URI(browseField.getText())); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); mailButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { String subject = percentEncode(subjectField.getText()); URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject); System.out.println(uri); Desktop.getDesktop().mail(uri); } catch (URISyntaxException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } }); JPanel buttonPanel = new JPanel(); ((FlowLayout) buttonPanel.getLayout()).setHgap(2); buttonPanel.add(openButton); buttonPanel.add(editButton); buttonPanel.add(printButton); add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2)); add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL)); add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0)); add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL)); add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL)); add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2)); add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2)); add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL)); pack(); }