作者psalter (Regular Expression)
看板java
标题Re: [问题] JProgressBar延迟
时间Thu Sep 27 15:29:31 2007
※ 引述《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