本文整理匯總了Java中java.awt.Desktop類的典型用法代碼示例。如果您正苦於以下問題:Java Desktop類的具體用法?Java Desktop怎麽用?Java Desktop使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Desktop類屬於java.awt包,在下文中一共展示了Desktop類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updaterUpdateAvailable
import java.awt.Desktop; //導入依賴的package包/類
@Override
public final void updaterUpdateAvailable(final String localVersion, final String remoteVersion) {
final String link = "https://github.com/" + GithubUpdater.UPDATER_GITHUB_USERNAME + "/" + GithubUpdater.UPDATER_GITHUB_REPO + "/releases/latest";
if(JOptionPane.showConfirmDialog(this, "<html>An update is available : v" + remoteVersion + " !<br/>" + "Would you like to visit " + link + " to download it ?</html>", Constants.APP_NAME, JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
try {
if(Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(link));
}
}
catch(final Exception ex) {
ex.printStackTrace(guiPrintStream);
ex.printStackTrace();
JOptionPane.showMessageDialog(ProjectsFrame.this, String.format(Constants.GUI_DIALOG_ERROR_MESSAGE, ex.getMessage()), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE);
}
}
}
示例2: actionPerformed
import java.awt.Desktop; //導入依賴的package包/類
@Override
protected void actionPerformed(GuiButton clickedButton) throws IOException {
if (clickedButton.id == 0) {
try {
String link = "https://github.com/Moudoux/EMC-Installer/releases";
if (clientInfo.get("updateLinkOverride").getAsBoolean()) {
link = clientInfo.get("website").getAsString();
}
Desktop.getDesktop().browse(new URL(link).toURI());
} catch (Exception e) {
;
}
Minecraft.getMinecraft().shutdown();
}
Minecraft.getMinecraft().displayGuiScreen(null);
super.actionPerformed(clickedButton);
}
示例3: editDESKTOP
import java.awt.Desktop; //導入依賴的package包/類
private static boolean editDESKTOP(File file) {
logOut("Trying to use Desktop.getDesktop().edit() with " + file);
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.EDIT)) {
logErr("EDIT is not supported.");
return false;
}
Desktop.getDesktop().edit(file);
return true;
} catch (Throwable t) {
logErr("Error using desktop edit.", t);
return false;
}
}
示例4: start
import java.awt.Desktop; //導入依賴的package包/類
@Override public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Simple Web Server");
BorderPane root = new BorderPane();
TextArea area = new TextArea();
root.setCenter(area);
ToolBar bar = new ToolBar();
Button openInBrowser = FXUIUtils.createButton("open-in-browser", "Open in External Browser", true);
openInBrowser.setOnAction((event) -> {
try {
Desktop.getDesktop().browse(URI.create(webRoot));
} catch (IOException e) {
e.printStackTrace();
}
});
Button changeRoot = FXUIUtils.createButton("fldr_closed", "Change Web Root", true);
changeRoot.setOnAction((event) -> {
DirectoryChooser chooser = new DirectoryChooser();
File showDialog = chooser.showDialog(primaryStage);
if (showDialog != null)
server.setRoot(showDialog);
});
bar.getItems().add(openInBrowser);
bar.getItems().add(changeRoot);
root.setTop(bar);
System.setOut(new PrintStream(new Console(area)));
System.setErr(new PrintStream(new Console(area)));
area.setEditable(false);
primaryStage.setScene(new Scene(root));
primaryStage.setOnShown((e) -> startServer(getParameters().getRaw()));
primaryStage.show();
}
示例5: onActionClickAliasHyperlink
import java.awt.Desktop; //導入依賴的package包/類
public void onActionClickAliasHyperlink() {
LoggerFacade.getDefault().debug(this.getClass(), "On action click [Alias] Hyperlink"); // NOI18N
if (
Desktop.isDesktopSupported()
&& Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)
) {
try {
final URL url = new URL(link.getUrl());
Desktop.getDesktop().browse(url.toURI());
} catch (IOException | URISyntaxException ex) {
LoggerFacade.getDefault().error(this.getClass(), "Can't open url: " + link.getUrl(), ex); // NOI18N
}
} else {
LoggerFacade.getDefault().warn(this.getClass(), "Desktop.isDesktopSupported() isn't supported");
}
}
示例6: onClick
import java.awt.Desktop; //導入依賴的package包/類
@Override
public void onClick(ActionEvent arg0)
{
try
{
URI v_URI = URI.create(AppMain.$SourceCode);
Desktop v_Desktop = Desktop.getDesktop();
// 判斷係統桌麵是否支持要執行的功能
if ( v_Desktop.isSupported(Desktop.Action.BROWSE) )
{
// 獲取係統默認瀏覽器打開鏈接
v_Desktop.browse(v_URI);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例7: browse
import java.awt.Desktop; //導入依賴的package包/類
/**
* Browse the given URL
*
* @param url url
* @param name title
*/
public static void browse(final URL url, final String name) {
if (Desktop.isDesktopSupported()) {
try {
// need this strange code, because the URL.toURI() method have
// some trouble dealing with UTF-8 encoding sometimes
final URI uri = new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url.getQuery(), url.getRef());
Desktop.getDesktop().browse(uri);
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
JOptionPane.showMessageDialog(null, Resources.getLabel("error.open.url", name));
}
} else {
JOptionPane.showMessageDialog(null, Resources.getLabel("error.open.url", name));
}
}
示例8: jButtonIniciarActionPerformed
import java.awt.Desktop; //導入依賴的package包/類
private void jButtonIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIniciarActionPerformed
try {
// Consumiendo web service
String json = iniciarServidor();
user = new Gson().fromJson(json, Pc.class);
System.out.println("Recibido: " + user);
jLabel1.setForeground(Color.green);
Desktop.getDesktop().browse(new URI("http://" + ip + ":" + user.getPuertoPHP() + "/phpmyadmin"));
url.setText("http://" + ip + ":" + user.getPuertoPHP() + "/phpmyadmin");
jlabelSQL.setText("PuertoSQL: " + user.getPuertoSQL());
this.setTitle("App [ID:" + user.getId() + "]");
} catch (IOException | URISyntaxException ex) {
Logger.getLogger(VentanaPrincipal.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例9: openExplorer
import java.awt.Desktop; //導入依賴的package包/類
/**
* Open an Explorer with the given Path
*
* @param directoryPath - Path to open
* @return Open-Explorer ActionListener
*/
static ActionListener openExplorer(String directoryPath) {
return e -> {
Desktop desktop = Desktop.getDesktop();
try {
desktop.open(new java.io.File(File.ensureDSonEndOfPath(directoryPath)).getAbsoluteFile());
} catch(Exception ex) {
ex.printStackTrace();
ErrorWindow errorWindow = new ErrorWindow(
"Unable to open the File-Explorer with the Directory: " + directoryPath,
ErrorWindow.ERROR_LEVEL_ERROR,
false
);
errorWindow.show();
}
};
}
示例10: openInBrowser
import java.awt.Desktop; //導入依賴的package包/類
/**
* If possible this method opens the default browser to the specified web
* page. If not it notifies the user of webpage's url so that they may
* access it manually.
*
* @param message Error message to display
* @param uri
*/
public static void openInBrowser(String message, URI uri) {
try {
java.util.logging.Logger.getLogger(Help.class.getName()).log(Level.INFO, "Opening url {0}", uri);
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri);
} else {
throw new UnsupportedOperationException("Desktop Api Not supported in this System");
}
} catch (Exception e) {
java.util.logging.Logger.getLogger(Help.class.getName()).log(Level.WARNING, null, e);
// Copy URL to the clipboard so the user can paste it into their browser
Utils.copyTextToClipboard(uri.toString());
// Notify the user of the failure
JOptionPane.showMessageDialog(null, message + "\n"
+ "The URL has been copied to your clipboard, simply paste into your browser to access.\n"
+ "Webpage: " + uri);
}
}
示例11: mouseClicked
import java.awt.Desktop; //導入依賴的package包/類
@Override
public void mouseClicked(MouseEvent e) {
JTable table = (JTable) e.getSource();
Point pt = e.getPoint();
int ccol = table.columnAtPoint(pt);
int crow = table.rowAtPoint(pt);
Object value = table.getValueAt(crow, ccol);
if (value instanceof URL) {
URL url = (URL) value;
try {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().browse(url.toURI());
}
} catch (Exception ex) {
throw new IllegalStateException(ex);
}
}
}
示例12: mouseClicked
import java.awt.Desktop; //導入依賴的package包/類
@Override
public void mouseClicked(MouseEvent e)
{
try
{
Desktop desktop = java.awt.Desktop.getDesktop();
URI uri = new java.net.URI(href);
desktop.browse(uri);
}
catch( Exception ex )
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Unable to open link in the system browser",
"Could not follow link", JOptionPane.ERROR_MESSAGE);
}
}
示例13: mouseClicked
import java.awt.Desktop; //導入依賴的package包/類
@Override
public void mouseClicked(MouseEvent e)
{
if( e.getSource() == preamble )
{
try
{
Desktop desktop = java.awt.Desktop.getDesktop();
URI uri = new java.net.URI(CANVAS_SIGNUP_URL);
desktop.browse(uri);
}
catch( Exception ex )
{
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Unable to open link in the system browser",
"Could not follow link", JOptionPane.ERROR_MESSAGE);
}
}
}
示例14: standardOpen
import java.awt.Desktop; //導入依賴的package包/類
public void standardOpen()
{
AccessController.doPrivileged(new PrivilegedAction<Object>()
{
@Override
public Object run()
{
try
{
debug("using Desktop.open");
Desktop.getDesktop().open(tempFile);
}
catch( Exception io )
{
logException("Error opening file", io);
}
return null;
}
}, openPermissionContext);
}
示例15: openDESKTOP
import java.awt.Desktop; //導入依賴的package包/類
private static boolean openDESKTOP(File file) {
logOut("Trying to use Desktop.getDesktop().open() with " + file.toString());
try {
if (!Desktop.isDesktopSupported()) {
logErr("Platform is not supported.");
return false;
}
if (!Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
logErr("OPEN is not supported.");
return false;
}
Desktop.getDesktop().open(file);
return true;
} catch (Throwable t) {
logErr("Error using desktop open.", t);
return false;
}
}