下面列出了java.awt.Desktop#browse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void jLabel_webMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_webMouseClicked
// TODO add your handling code here:
try {
URI uri = new URI("http://www.meteothink.org");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
if (desktop != null) {
desktop.browse(uri);
}
} catch (URISyntaxException ex) {
Logger.getLogger(FrmAbout.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ioe) {
}
}
private void jLabel_webMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel_webMouseClicked
// TODO add your handling code here:
try {
URI uri = new URI("http://www.meteothink.org");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
}
if (desktop != null) {
desktop.browse(uri);
}
} catch (URISyntaxException ex) {
Logger.getLogger(FrmAbout.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ioe) {
}
}
private static void open(URI uri) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (IOException e) {
JOptionPane.showMessageDialog(null,
"URL: " + uri,
"Please use your browser to visit:", JOptionPane.WARNING_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null,
"URL: " + uri,
"Please use your browser to visit:", JOptionPane.WARNING_MESSAGE);
}
}
@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();
}
}
/**
* Launches a web browser to browse a site.
*
* @param uri URI the browser should open.
*/
public void launch (URI uri)
{
String osName = System.getProperty("os.name");
if (true) {
logger.info("Desktop.browse {} with {} on {}", uri, this, osName);
try {
Desktop desktop = Desktop.getDesktop();
desktop.browse(uri);
} catch (IOException ex) {
logger.warn("Could not launch browser " + uri, ex);
}
} else {
// Delegate to BareBonesBrowserLaunch-like code
logger.info("openURL {} with {} on {}", uri, this, osName);
openURL(uri.toString());
}
}
private static void openWebPage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (IOException e) {
throw new IllegalStateException("Problem opening " + uri.toString(), e);
}
}
}
/**
* Open the help page.
*/
void doHelp() {
try {
URI u = new URI("https://github.com/akarnokd/open-ig/wiki/Campaign-editor");
if (Desktop.isDesktopSupported()) {
Desktop d = Desktop.getDesktop();
d.browse(u);
} else {
JOptionPane.showConfirmDialog(this, u);
}
} catch (IOException | URISyntaxException ex) {
Exceptions.add(ex);
}
}
public static void main(String[] args) throws Exception {
URI uri = new URI("http://www.nytimes.com");
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
desktop.browse(uri);
}
}
public static void openURI(URI uri) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (IOException e) {
Messages.showException(e);
}
}
}
private static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public void execute(Wandora wandora, Context context) throws TopicMapException {
try {
String location = getWebLocation(context);
if(location != null && location.length() > 0) {
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(location));
}
}
catch(Exception ex) {
log(ex);
}
}
/**
* @param connection
* @throws SQLException
* @throws IOException
*/
public static void openHtmlForConnection(Connection connection) throws SQLException, IOException {
DatabaseMetaData databaseMetaData = connection.getMetaData();
String databaseProductName = databaseMetaData.getDatabaseProductName();
System.out.println(databaseProductName);
System.out.println(SystemUtils.JAVA_VERSION);
System.out.println(new Date() + " Begin...");
File file = new File("c:\\test\\sc.out.html");
SchemaInfoAccessor schemaInfoAccessor = new SchemaInfoAccessor(connection, "sampledb");
System.out.println("schemaInfoAccessor: " + schemaInfoAccessor.isAccessible());
if (schemaInfoAccessor.isAccessible()) {
SchemaInfoSC schemaInfoSC = schemaInfoAccessor.getSchemaInfoSC();
String table = null; // customer;
// table = "orderlog";
schemaInfoSC.buildOnFile(file, AceQLOutputFormat.html, table);
System.out.println(schemacrawler.Version.getVersion());
System.out.println(new Date() + " Done: " + file);
Desktop desktop = Desktop.getDesktop();
desktop.browse(file.toURI());
} else {
System.out.println("Can not get full Schema info: " + schemaInfoAccessor.getFailureReason());
}
}
public static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void doOpenDocumentation() {
try {
Desktop desktop = Desktop.getDesktop();
desktop.browse(new URI(DOCUMENTATION_URL));
} catch (URISyntaxException | IOException ex) {
}
}
public static void launchBrowser(String url) {
Desktop desktop;
if (Desktop.isDesktopSupported()) {
desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(url));
} catch (IOException | URISyntaxException ex) {
Logger.getLogger("utilFunctions.launchBrowser").log(Level.SEVERE, null, ex);
}
}
}
public static void openWebpage(URI uri) {
if (isBrowseSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
} else {
System.out.println("Desktop does not support opening of a browser :/ open " + uri + " yourself");
}
}
private void openButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openButtonMouseReleased
Desktop dt = Desktop.getDesktop();
if(dt != null) {
try {
dt.browse(new URI("http://www.hel.fi/palvelukartta"));
}
catch(Exception e) {
e.printStackTrace();
}
}
}
/** Open the project issue page. */
void doReport() {
try {
Desktop d = Desktop.getDesktop();
d.browse(new URI(ISSUE_LIST));
} catch (Throwable ex) {
doReportDialog();
}
}
public static void main(String[] args) throws Exception {
// Setting up prometheus stats collector.
PrometheusStatsCollector.createAndRegister();
// Setting up HTTP server that would serve http://localhost:8080 requests.
HTTPServer srv = new HTTPServer(HOST, PORT, true);
IgniteConfiguration cfg = new IgniteConfiguration();
// Setting up OpenCensus exporter.
OpenCensusMetricExporterSpi openCensusMetricExporterSpi = new OpenCensusMetricExporterSpi();
// Metrics written to the collector each 1 second.
openCensusMetricExporterSpi.setPeriod(PERIOD);
cfg.setMetricExporterSpi(openCensusMetricExporterSpi);
try (Ignite ignite = Ignition.start(cfg)) {
// Creating cache.
IgniteCache<Integer, Integer> cache = ignite.createCache("my-cache");
// Putting some data to the cache.
for (int i = 0; i < 100; i++)
cache.put(i, i);
// Sleeping for 2 sec to make sure data exported to the prometheus.
Thread.sleep(2 * PERIOD);
// If desktop supported opens up page with the metrics.
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(METRICS_URL));
Thread.sleep(2 * PERIOD);
}
catch (IOException | URISyntaxException e) {
throw new RuntimeException(e);
}
}
else {
// In case desktop disabled printing URL content.
URLConnection conn = new URL(METRICS_URL).openConnection();
try (InputStream in = conn.getInputStream()) {
String content = IOUtils.toString(in, conn.getContentEncoding());
System.out.println(content);
}
}
}
}
@Override
protected Void doInBackground() throws Exception {
Desktop desktop = java.awt.Desktop.getDesktop();
desktop.browse(uri);
return null;
}