{"id":95,"date":"2007-02-27T11:01:43","date_gmt":"2007-02-27T03:01:43","guid":{"rendered":"http:\/\/127.0.0.1\/website_linux\/blog\/?p=95"},"modified":"2007-02-27T11:01:43","modified_gmt":"2007-02-27T03:01:43","slug":"vector%e7%b1%bb%e5%9c%a8java%e7%bc%96%e7%a8%8b%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/opgogo.com\/blog2\/?p=95","title":{"rendered":"Vector\u7c7b\u5728Java\u7f16\u7a0b\u4e2d\u7684\u5e94\u7528"},"content":{"rendered":"<p>Vector\u7c7b\u5728Java\u7f16\u7a0b\u4e2d\u7684\u5e94\u7528<\/p>\n<p>&#8212;- Vector \u7c7b \u63d0 \u4f9b \u4e86 \u5b9e \u73b0 \u53ef \u589e \u957f \u6570 \u7ec4 \u7684 \u529f \u80fd\uff0c \u968f \u7740 \u66f4 \u591a \u5143 \u7d20 \u52a0 \u5165 \u5176 \u4e2d\uff0c \u6570 \u7ec4 \u53d8 \u7684 \u66f4 \u5927\u3002 \u5728 \u5220 \u9664 \u4e00 \u4e9b \u5143 \u7d20 \u4e4b \u540e\uff0c \u6570 \u7ec4 \u53d8 \u5c0f\u3002<\/p>\n<p>Vector \u6709 \u4e09 \u4e2a \u6784 \u9020 \u51fd \u6570\uff0c<br \/>\npublic Vector(int initialCapacity,int capacityIncrement)<br \/>\npublic Vector(int initialCapacity)<br \/>\npublic Vector()<\/p>\n<p>&#8212;- Vector \u8fd0 \u884c \u65f6 \u521b \u5efa \u4e00 \u4e2a \u521d \u59cb \u7684 \u5b58 \u50a8 \u5bb9 \u91cfinitialCapacity\uff0c \u5b58 \u50a8 \u5bb9 \u91cf \u662f\u4ee5capacityIncrement \u53d8 \u91cf \u5b9a \u4e49 \u7684 \u589e \u91cf \u589e \u957f\u3002 \u521d \u59cb \u7684 \u5b58 \u50a8 \u5bb9 \u91cf \u548ccapacityIncrement \u53ef \u4ee5 \u5728Vector \u7684 \u6784 \u9020 \u51fd \u6570 \u4e2d \u5b9a \u4e49\u3002 \u7b2c \u4e8c \u4e2a \u6784 \u9020 \u51fd \u6570 \u53ea \u521b \u5efa \u521d \u59cb \u5b58 \u50a8 \u5bb9 \u91cf\u3002 \u7b2c \u4e09 \u4e2a \u6784 \u9020\u51fd \u6570 \u65e2 \u4e0d \u6307 \u5b9a \u521d \u59cb \u7684 \u5b58 \u50a8 \u5bb9 \u91cf \u4e5f \u4e0d \u6307 \u5b9acapacityIncrement\u3002<\/p>\n<p>&#8212;- Vector \u7c7b \u63d0 \u4f9b \u7684 \u8bbf \u95ee \u65b9 \u6cd5 \u652f \u6301 \u7c7b \u4f3c \u6570 \u7ec4 \u8fd0 \u7b97 \u548c \u4e0eVector \u5927 \u5c0f \u76f8 \u5173 \u7684 \u8fd0 \u7b97\u3002 \u7c7b \u4f3c \u6570 \u7ec4\u7684 \u8fd0 \u7b97 \u5141 \u8bb8 \u5411 \u91cf \u4e2d \u589e \u52a0\uff0c \u5220 \u9664 \u548c \u63d2 \u5165 \u5143 \u7d20\u3002 \u5b83 \u4eec \u4e5f \u5141 \u8bb8 \u6d4b \u8bd5 \u77e2 \u91cf \u7684 \u5185 \u5bb9 \u548c \u68c0 \u7d22 \u6307 \u5b9a \u7684\u5143 \u7d20\uff0c \u4e0e \u5927 \u5c0f \u76f8 \u5173 \u7684 \u8fd0 \u7b97 \u5141 \u8bb8 \u5224 \u5b9a \u5b57 \u8282 \u5927 \u5c0f \u548c \u77e2 \u91cf \u4e2d \u5143 \u7d20 \u4e0d \u6570 \u76ee\u3002<\/p>\n<p>&#8212;- \u73b0 \u9488 \u5bf9 \u7ecf \u5e38 \u7528 \u5230 \u7684 \u5bf9 \u5411 \u91cf \u589e\uff0c \u5220\uff0c \u63d2 \u529f \u80fd \u4e3e \u4f8b \u63cf \u8ff0\uff1a<\/p>\n<p>addElement(Object obj)<\/p>\n<p>&#8212;- \u628a \u7ec4 \u4ef6 \u52a0 \u5230 \u5411 \u91cf \u5c3e \u90e8\uff0c \u540c \u65f6 \u5927 \u5c0f \u52a01\uff0c \u5411 \u91cf \u5bb9 \u91cf \u6bd4 \u4ee5 \u524d \u59271<\/p>\n<p>ins&#101;rtElementAt(Object obj, int index)<\/p>\n<p>&#8212;- \u628a \u7ec4 \u4ef6 \u52a0 \u5230 \u6240 \u5b9a \u7d22 \u5f15 \u5904\uff0c \u6b64 \u540e \u7684 \u5185 \u5bb9 \u5411 \u540e \u79fb \u52a81 \u4e2a \u5355 \u4f4d<\/p>\n<p>setElementAt(Object obj, int index)<\/p>\n<p>&#8212;- \u628a \u7ec4 \u4ef6 \u52a0 \u5230 \u6240 \u5b9a \u7d22 \u5f15 \u5904\uff0c \u6b64 \u5904 \u7684 \u5185 \u5bb9 \u88ab \u4ee3 \u66ff\u3002<\/p>\n<p>&#8212;- removeElement(Object obj) \u628a \u5411 \u91cf \u4e2d \u542b \u6709 \u672c \u7ec4 \u4ef6 \u5185 \u5bb9 \u79fb \u8d70\u3002<\/p>\n<p>&#8212;- removeAllElements() \u628a \u5411 \u91cf \u4e2d \u6240 \u6709 \u7ec4 \u4ef6 \u79fb \u8d70\uff0c \u5411 \u91cf \u5927 \u5c0f \u4e3a0\u3002<\/p>\n<p>&#8212;- \u4f8b \u5982\uff1a<\/p>\n<p>import java.lang.System;<br \/>\nimport java.util.Vector;<br \/>\nimport java.util.Emumeration;<br \/>\npublic class Avector{<br \/>\npublic static void main(String args[])<br \/>\n{<br \/>\n0. Vector v=new Vector();<br \/>\n1. v.addElement(&#8220;one&#8221;);<br \/>\n2. addElement(&#8220;two&#8221;);<br \/>\n3. v.addElement(&#8220;three&#8221;);<br \/>\n4. v.ins&#101;rtElementAt(&#8220;zero&#8221;,0);<br \/>\n5. v.ins&#101;rtElementAt(&#8220;oop&#8221;,3);<br \/>\n6. v.setElementAt(&#8220;three&#8221;,3);<br \/>\n7. v.setElementAt(&#8220;four&#8221;,4);<br \/>\n8. v.removeAllElements();<br \/>\n}<br \/>\n}<br \/>\nVector\u4e2d\u7684\u53d8\u5316\u60c5\u51b5\uff1a<br \/>\n1. one 2. one 3. one 4. zero 5.zero 6. zero 7. zero<br \/>\n8.<br \/>\ntwo two one one one one<br \/>\nthree two two two two<br \/>\nthree oop three three<br \/>\nthree three four<\/p>\n<p>&#8212;- \u53e6 \u5916\uff0cVector \u5728 \u53c2 \u6570 \u4f20 \u9012 \u4e2d \u53d1 \u6325 \u7740 \u4e3e \u8db3 \u8f7b \u91cd \u7684 \u4f5c \u7528\u3002<\/p>\n<p>&#8212;- \u5728Applet \u4e2d \u6709 \u4e00 \u5757 \u753b \u5e03(Canvas) \u548c \u4e00 \u4e2a(Panel), \u800cPanel \u4e2d \u653e \u7740 \u7528 \u6237 \u8981 \u8f93 \u5165 \u7684 \u4fe1 \u606f\uff0c\u6839 \u636e \u8fd9 \u4e9b \u4fe1 \u606f \u628a \u53c2 \u6570 \u4f20 \u9012 \u5230canvas \u4e2d\uff0c \u8fd9 \u65f6 \u5728Java \u4e2d \u7528 \u4e00 \u4e2a \u63a5 \u53e3\uff08Interface\uff09, \u800c \u5728\u63a5 \u53e3 \u4e2d \u9700 \u7528 \u4e00 \u4e2aVector \u53bb \u4f20 \u9012 \u8fd9 \u4e9b \u53c2 \u6570\u3002 \u53e6 \u5916\uff0c \u5728 \u4e00 \u4e2a \u7c7b \u5411 \u53e6 \u4e00 \u4e2a \u7c7b \u53c2 \u6570 \u4f20 \u9012 \u5c31 \u53ef \u4ee5\u7528 \u8fd9 \u79cd \u65b9 \u6cd5\u3002<\/p>\n<p>&#8212;- \u4f8b \u5982\uff1a<\/p>\n<p>import java.util.Vector<br \/>\ninterface codesel&#101;ct{<br \/>\nVector codesel&#101;ct=new Vector();<br \/>\n}<br \/>\n\u663e\u793a\u6570\u5b66\u4fe1\u606f<br \/>\nVector(0)\u5b58\u5165\u5b66\u751f\u7f16\u53f7<br \/>\nVector(1)\u5b58\u5165\u5b66\u79d1<\/p>\n<p>&#8212;- \u5728Panel \u4e2d \u5f53 \u7528 \u6237 \u5728 TextField \u548cChoice \u4e2d \u9009 \u62e9 \u81ea \u5df1 \u6240 \u8981 \u6c42 \u7684 \u5185 \u5bb9\uff0c \u7a0b \u5e8f \u4e2d<\/p>\n<p>&#8212;- \u901a \u8fc7 \u4e8b \u4ef6 \u54cd \u5e94 \u628a \u503c \u4f20 \u5230 \u5411 \u91cfVector \u4e2d\u3002<\/p>\n<p>&#8212;- \u5047 \u82e5 \u5728Panel \u7c7b \u4e2d\uff1a<\/p>\n<p>public void codepanel extends Panel{<br \/>\npublic void init()<br \/>\n{<br \/>\n**.<br \/>\nTextField s=new TextField();<br \/>\nChoice c=new Choice();<br \/>\nc. addItem(&#8220;\u8bed\u6587&#8221;);<br \/>\nc.addItem(&#8220;\u6570\u5b66&#8221;);<br \/>\nc.addItem(&#8220;\u653f\u6cbb&#8221;);<br \/>\nadd(s);<br \/>\nadd (c);<br \/>\n**<br \/>\n}<\/p>\n<p>public boolean handleEvent(Event event){<br \/>\nif(event.id==Event.ACTION_EVENT){<br \/>\nif(event.target.instanceof Textfield)<br \/>\n{<br \/>\ncoderesult.setElementAt(s.getText(),0);<br \/>\n}<br \/>\nelse if(event.target intanceof Choice)<br \/>\n{<br \/>\ncoderesult.setElementAt(new Integer(c.getSel&#101;ctedIndex()),1);<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>&#8212;- \u8fd9 \u65f6\uff0c \u5411 \u91cf \u4e2d \u5df2 \u7ecf \u5b58 \u5165 \u5b66 \u751f \u7f16 \u53f7 \u548c \u5b66 \u79d1 \u7d22 \u5f15 \u53f7\uff080 \u4e3a \u8bed \u6587\uff0c1 \u4e3a \u6570 \u5b66\uff0c2 \u4e3a \u653f \u6cbb\uff09\u3002<\/p>\n<p>&#8212;- \u800c \u5728Canvas \u4e2d \u5f97 \u5230 \u6b64 \u503c\uff0c<\/p>\n<p>public class codecanvas extends Canvas{<\/p>\n<p>public void code{<br \/>\n}<br \/>\npublic void paint{<\/p>\n<p>String str;<br \/>\nint t;<br \/>\nstr=(String)coderesult.elementAt(0);<br \/>\nt=(new Integer(codesel&#101;ct.elementAt(1).toString())).intValue();<br \/>\nif(t==0)<br \/>\n{<br \/>\n\u663e\u793a\u8bed\u6587\u4fe1\u606f<br \/>\n}<br \/>\nelse if(t==1)<br \/>\n{<br \/>\n\u663e\u793a\u6570\u5b66\u4fe1\u606f<\/p>\n<p>}<br \/>\nelse if(t==2)<br \/>\n{<br \/>\n\u663e\u793a\u653f\u6cbb\u4fe1\u606f<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Vector\u7c7b\u5728Java\u7f16\u7a0b\u4e2d\u7684\u5e94\u7528 &#8212;- Vector \u7c7b \u63d0 \u4f9b \u4e86 \u5b9e \u73b0 \u53ef \u589e \u957f \u6570 \u7ec4 \u7684 \u529f \u80fd\uff0c \u968f \u7740 \u66f4 \u591a \u5143 \u7d20 \u52a0 \u5165 \u5176 \u4e2d\uff0c \u6570 \u7ec4 \u53d8 \u7684 \u66f4 \u5927\u3002 \u5728 &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[28],"tags":[],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-computer"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=95"}],"version-history":[{"count":0,"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=\/wp\/v2\/posts\/95\/revisions"}],"wp:attachment":[{"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opgogo.com\/blog2\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}