2011年3月26日 星期六

[Java] HashMap走訪器

HashMap hm = new HashMap();
hm.put("a", 1);
hm.put("b", 2);
hm.put("c", 3);
Set set = new HashSet();
set =  hm.keySet();
Iterator it = set.iterator();

String s;
while (it.hasNext()) {
    s = it.next().toString();
    System.out.println( s + " = " + hm.get(s).toString());
}

2011年3月12日 星期六

[Java] ArrayList轉Array

ArrayList al = new ArrayList();
al.add("a");
al.add("b");
al.add("c");

//方法一(推薦)
String a[] = (String[]) al.toArray(new String[0]);

//方法二
String a[] = new String[al.size()];
a = al.toArray(a);

//測試

        for (String s : a) {
            System.out.println(s);
        }

2011年3月11日 星期五

[Java]取小數點第n位

說明兩數相除取到小數第n位
範例為取小數第3位
int a1=5,a2=3;
System.out.println(((float)(a1*1000/a2)/1000));
執行結果:
 1.666

2011年3月9日 星期三

使用Google協作平台來播放Flash Mp3 Player方法

本文適用有google帳號的人,若有其他網路空間(ex: Hinet)能存放檔案並外連,則使用其他網路空間放Flash Mp3 Player會較為容易。
  1. 首先在協作平台,建立新頁面→檔案庫
  2. 將播放器mp3player.swf與播放清單mp3player.xml上傳到檔案庫
  3. 張貼以下語法(需部落格或網站支援),紅色為播放器位置
  4. 藍色為xml位置,必須要是原始位置才能順利載入xml,使用google chrome瀏覽器的話可以先下載一次剛才上傳的xml檔案,然後看下載紀錄,左鍵雙擊反白xml檔案下載位置,在貼入語法即可
張貼語法範例
<embed flashvars="playlist=https://3684244539618411591-a-1802744773732722657-s-sites.googlegroups.com/site/sd8101627/box/mp3player.xml?attachauth=ANoY7crnSLvBCUEOtS2pELRz3TT7MKB_DJyXo-kt9TMsFebPC1eybFdA8tcSz0AV8GlBVnlZzhs-nZKU3DFtwpmzYeHmxzCBK6OzBaUUs1PCAEKxH8Mo-HLGiKpFZBLIWqZDyk_vEBMkixS1qH2ZJdyq5Q921Ep-MhfUHmgQIeon0a3WJewsJFx0NKN16_kIyxsBuheqSPpojGbSMG-aaXiD3FnRFC1QjQ%3D%3D&attredirects=0&d=1" height="210" src="https://sites.google.com/site/sd8101627/box/mp3player.swf" width="160" wmode="transparent&quot;"></embed>


播放器可自行更換

播放清單內容如下

<?xml version="1.0" encoding="UTF-8"?>
<player showDisplay="yes" showPlaylist="yes" autoStart="random">
<song path="mp3的網路位置" title="mp3的標題" />
          <song path="自行延伸...                                           " />
</player>

 mp3的網路位置必須為直接下載連結,mp3的標題可自訂,最好使用支援Unicode的編輯器(如notepad++)才能正常顯示中文