java 板


LINE

※ 引述《slalala (ptt不是丁丁知識+)》之銘言: : 最近我也碰到這個碗糕了( ‵□′)───C<─___-)||| : 提供一個心得。 : 我對AWT不懂,只是爬文得知這個問題。 : 因為我要弄得程式必須還要即時的JTABLE更新, : 我發現把rapaint放在跟 JProgressBar同一個Thread裡面 : JProgressBar會變成只跑第1次,然後繼續delay到最後跑100%... : 簡單說要是這樣寫,可能就要多一個Thread囉... : 不過我用DefaultTableModel addROW()就解決這個問題了~_~ : 另外問一個vector的小問題 : 我英文太差嗎XD : API我看不出Vector.add(OBJECT) : 跟Vector.addElement(OBJECT)的差別; 這2個method的結果是一樣的 addElement() : Adds the specified component to the end of this vector 將物件加到Vector的尾巴 This method is identical in functionality to the add(Object) method (which is part of the List interface) 此method與 add()的功能是一樣的 真要說差別的話: 1. add() method有作overload, 有 add(index,obkect) 與 add(object) 2個,概念上是 以指定位置的方式insert物件,而add(object)只是省略指定位置,直接insert在最後 2. Vector是繼承AbstractList與實作List interface, 所以必須實作add() method 也就是add()是原本List結構所規範要有的method 3. 承2, add(Object)這個method是Collecction interface所定義的,這個method會回傳 boolean, 如果true的話,表示此Collection結構發生改變: "Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)" (參Collection interface) 至於addElement() 並沒有回傳值 但是就Vector的使用上,並沒有差別,因為Vector並不會限制size多大,每一次的 add()都會增加size "Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added." 可以參考一下Collection add() API 其實蠻有意思的,包括加入重覆物件行為 的規範。其實可以提供我們在開interface的借鏡 : 還有 ElementAt(int)跟get(int)的差別 功能上也是一樣, get()是List interface規範的 最後,就使用上差別來說,用那個method會取決於你宣告的class type(靜態型別)是那種 如果宣告是: List list = new Vector(); list.add(o); list.get(0); 那麼就無法使用 addElement()或elementAt()了,因為class type是list, 只能使用 list.add() or list.get() 如果宣告是: Vector vec = new Vector(); 那麼2種method都能用 不過建議使用List宣告,因為實際型別可以更換而不會影響後面程式的存取,例如 如果某天你要改用LinkedList或ArrayList 後面程式不會有更動 List list = new ArrayList(); list.add(o); list.get(0); : 耶 : ....clear() 跟removeAllElements() : 我好像還看的出後者是將空間釋放.... : 有人可以提示我一下嗎? : 感謝 這2個method解釋同上囉~ --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.81.16.30
1F:推 slalala:原來如此 感謝﹨(╯▽╰)∕ 09/27 15:38
2F:推 GERRYccc:真專業...(讚~) 09/28 12:06







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Soft_Job站內搜尋

TOP