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