Swing/Desktop のバックアップの現在との差分(No.5)
TITLE:Desktopでブラウザを起動
Posted by aterai at 2007-02-19
Desktopでブラウザを起動
JDK 6 で導入されたDesktopを使ってブラウザを起動します。- category: swing folder: Desktop title: Desktopでブラウザを起動 tags: [Desktop, Html] author: aterai pubdate: 2007-02-19T16:02:04+09:00 description: JDK 6で導入されたDesktopを使ってブラウザを起動します。 image:
概要
JDK 6
で導入されたDesktop
を使ってブラウザを起動します。
- &jar;
- &zip;
Screenshot
Advertisement
サンプルコード
#spanend
#spandel
if(!Desktop.isDesktopSupported()) return;
#spanend
#spandel
try{
#spanend
Desktop.getDesktop().browse(new URI(href));
#spandel
}catch(IOException ioe) {
#spanend
ioe.printStackTrace();
#spandel
}catch(URISyntaxException use) {
#spanend
use.printStackTrace();
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
if (Desktop.isDesktopSupported()) {
#spanend
try {
Desktop.getDesktop().browse(new URI(href));
} catch (IOException | URISyntaxException ex) {
ex.printStackTrace();
}
}
解説
Desktopを使用することで、ブラウザのほかにも、メーラーや拡張子に関連付けられたデフォルトのアプリケーションを起動することが出来るようになります。解説
-
Desktop
を使用することで拡張子に関連付けられたデフォルトのアプリケーションを起動可能 -
OS
毎に対応するアプリケーションをRuntime.getRuntime().exec(String[])
で実行せずにブラウザなどを起動可能