借助瀏覽器控件利用CSS和javascript設(shè)計(jì)桌面程序界面
Posted on 2010-03-04 15:08 penngo 閱讀(3141) 評(píng)論(0) 編輯 收藏 所屬分類: Java使用javascript和CSS,可以把web的頁(yè)面設(shè)計(jì)搞得很漂亮;但如果你想把CS的桌面程序搞得漂亮點(diǎn),這個(gè)還真不容易。雖然像swing
可以更換外觀http://www.open-open.com/61.htm讓界面漂亮點(diǎn),但這些也只是讓swing控件漂亮點(diǎn)。對(duì)于程序的整體布局等,相對(duì)
javascript和CSS做出來(lái)的頁(yè)面效果,實(shí)在顯得有點(diǎn)差。
本文是先通過(guò)tree.html設(shè)計(jì)好程序界面,再調(diào)用jdic中的瀏覽器控件org.jdesktop.jdic.browser.WebBrowser顯示tree.html
程序的功能主要是實(shí)現(xiàn)上一篇介紹的http://www.aygfsteel.com/pengo/archive/2010/01/26/310849.html
tree.html代碼
通過(guò)<a>標(biāo)記傳遞參數(shù),當(dāng)點(diǎn)擊C盤時(shí),URL將會(huì)變?yōu)?...../tree.html#explorer.exe c:
MenuTest.java代碼:
在webBrowser的WebBrowserListener事件中實(shí)現(xiàn)downloadCompleted方法,先獲取當(dāng)前頁(yè)的URL,通過(guò)分析URL后邊的參數(shù),獲得“#”符號(hào)后操作命令。
效果圖:

原代碼:HtmlFrame.src.rar
運(yùn)行程序:HtmlFrame.jar.rar
可以更換外觀http://www.open-open.com/61.htm讓界面漂亮點(diǎn),但這些也只是讓swing控件漂亮點(diǎn)。對(duì)于程序的整體布局等,相對(duì)
javascript和CSS做出來(lái)的頁(yè)面效果,實(shí)在顯得有點(diǎn)差。
本文是先通過(guò)tree.html設(shè)計(jì)好程序界面,再調(diào)用jdic中的瀏覽器控件org.jdesktop.jdic.browser.WebBrowser顯示tree.html
程序的功能主要是實(shí)現(xiàn)上一篇介紹的http://www.aygfsteel.com/pengo/archive/2010/01/26/310849.html
tree.html代碼
通過(guò)<a>標(biāo)記傳遞參數(shù),當(dāng)點(diǎn)擊C盤時(shí),URL將會(huì)變?yōu)?...../tree.html#explorer.exe c:
<span style="top: 213px; height: 211px; visibility: visible;" class="link"><div class="title">我的電腦</div>
<div style="visibility: hidden;" class="text">
<a href="#explorer.exe c:" class="alink">C盤</a> <br/>
<a href="#explorer.exe d:" class="alink">D盤</a> <br/>
<a href="#explorer.exe e:" class="alink">E盤</a> <br/>
<a href="#explorer.exe ::{208D2C60-3AEA-1069-A2D7-08002B30309D}" class="alink" >網(wǎng)上鄰居</a> <br/>
<a href="#explorer.exe ::{645FF040-5081-101B-9F08-00AA002F954E}" class="alink">回收站</a> <br/>
<a href="#notepad" class="alink">記事本</a> <br/>
</div>
</span>
<span style="top: 231px; height: 211px; visibility: visible;" class="link"><div class="title">關(guān)機(jī)管理</div>
<div style="visibility: hidden;" class="text">
<a href="#Shutdown.exe -s -t 00" class="alink">關(guān)機(jī)</a> <br/>
<a href="#Shutdown.exe -r -f -t 00" class="alink">重啟</a> <br/>
</div>
</span>
<div style="visibility: hidden;" class="text">
<a href="#explorer.exe c:" class="alink">C盤</a> <br/>
<a href="#explorer.exe d:" class="alink">D盤</a> <br/>
<a href="#explorer.exe e:" class="alink">E盤</a> <br/>
<a href="#explorer.exe ::{208D2C60-3AEA-1069-A2D7-08002B30309D}" class="alink" >網(wǎng)上鄰居</a> <br/>
<a href="#explorer.exe ::{645FF040-5081-101B-9F08-00AA002F954E}" class="alink">回收站</a> <br/>
<a href="#notepad" class="alink">記事本</a> <br/>
</div>
</span>
<span style="top: 231px; height: 211px; visibility: visible;" class="link"><div class="title">關(guān)機(jī)管理</div>
<div style="visibility: hidden;" class="text">
<a href="#Shutdown.exe -s -t 00" class="alink">關(guān)機(jī)</a> <br/>
<a href="#Shutdown.exe -r -f -t 00" class="alink">重啟</a> <br/>
</div>
</span>
MenuTest.java代碼:
在webBrowser的WebBrowserListener事件中實(shí)現(xiàn)downloadCompleted方法,先獲取當(dāng)前頁(yè)的URL,通過(guò)分析URL后邊的參數(shù),獲得“#”符號(hào)后操作命令。
public void downloadCompleted(WebBrowserEvent event) {
URL currentUrl = webBrowser.getURL();
if(currentUrl != null){
String cmd = currentUrl.toString();
if(cmd.indexOf("#") != -1){
cmd = cmd.substring(cmd.indexOf("#") + 1);
if(cmd.equals("exit")){
System.exit(0);
}
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
URL currentUrl = webBrowser.getURL();
if(currentUrl != null){
String cmd = currentUrl.toString();
if(cmd.indexOf("#") != -1){
cmd = cmd.substring(cmd.indexOf("#") + 1);
if(cmd.equals("exit")){
System.exit(0);
}
try {
Runtime.getRuntime().exec(cmd);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
效果圖:

原代碼:HtmlFrame.src.rar
運(yùn)行程序:HtmlFrame.jar.rar