﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-张慧的博客</title><link>http://www.blogjava.net/hongqiang/</link><description>张慧的博客</description><language>zh-cn</language><lastBuildDate>Tue, 19 May 2026 05:51:28 GMT</lastBuildDate><pubDate>Tue, 19 May 2026 05:51:28 GMT</pubDate><ttl>60</ttl><item><title>BS开发入门——CSS（层叠样式表）名称含义</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/16/385635.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Thu, 16 Aug 2012 14:29:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/16/385635.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385635.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/16/385635.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385635.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385635.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">CSS(Cascading Style Sheet) 层叠样式表，一种和Html联系非常大的标记语言，主要用户控制网页的样式，并能把样式和网页内容分离，因此能大大提高网页开发的效率。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">&nbsp; &nbsp; &nbsp; &nbsp;初识CSS，感觉这个名字有点难以理解，&#8220;样式表&#8221;理解起来比较容易，就是定义网页的样式，也可以叫风格，那层叠怎么理解呢？</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">&nbsp; &nbsp; &nbsp; &nbsp;这要从CSS的继承说起，学过面向对象的话，对继承一定不陌生，CSS的继承更简单一些：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">&nbsp; &nbsp;</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">在Html中各个标签可以看作是一个个容器，例如：</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></p><div bg_html"="" style="width: 1097px; line-height: 25px; text-align: left; "><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/xqf309/article/details/7873404#" title="view plain">view plain</a><a href="http://blog.csdn.net/xqf309/article/details/7873404#" title="copy">copy</a><a href="http://blog.csdn.net/xqf309/article/details/7873404#" title="print">print</a><a href="http://blog.csdn.net/xqf309/article/details/7873404#" title="?">?</a><div style="position: absolute; left: 438px; top: 617px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; font-size: 17px; "><span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">span</span>&nbsp;<span style="color: red; ">style</span>=<span style="color: blue; ">"font-size:18px;"</span><span style="color: #993300; font-weight: bold; ">&gt;</span><span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">p</span><span style="color: #993300; font-weight: bold; ">&gt;</span>详解CSS的<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">em</span><span style="color: #993300; font-weight: bold; ">&gt;</span>名称<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">em</span><span style="color: #993300; font-weight: bold; ">&gt;</span>含义<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">p</span><span style="color: #993300; font-weight: bold; ">&gt;</span><span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">span</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li></ol></div><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 18px; "><br /></span><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; font-size: 18px; ">&nbsp; &nbsp; &nbsp; &nbsp;这一句话中，&lt;p&gt;标签是一个大容器，里面有&lt;em&gt;标签 ，我们把&lt;p&gt;标签定义成父标签，那么&lt;em&gt;标签就成了子标签。当我对&lt;p&gt;标签（父标签）用CSS样式时，字标签会完全继承父标签的风格，当然这种关系可能会有更多层（上面的例子为两层）：</span><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><img src="http://my.csdn.net/uploads/201208/16/1345102188_3911.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 18px; ">这张图上，每个子标签都会继承父标签的样式，这种层层嵌套的关系，也就是CSS名称的含义。</span></p><img src ="http://www.blogjava.net/hongqiang/aggbug/385635.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-16 22:29 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/16/385635.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Android 多个ImageView图片层叠透明区域点击事件穿透</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/16/385634.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Thu, 16 Aug 2012 14:28:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/16/385634.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385634.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/16/385634.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385634.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385634.html</trackback:ping><description><![CDATA[<p align="left" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; background-color: #ffffff; "><strong>经常用到多个透明图片层叠，但又需要获取不同图片的点击事件，本文实现图片透明区域穿透点击事件。</strong></p><p align="left" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; background-color: #ffffff; ">效果图：</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><img alt="" src="http://my.csdn.net/uploads/201208/16/1345092577_4647.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;欢迎转载请说明转自：<a href="http://blog.csdn.net/aminfo/article/details/7872748" style="color: #ff9900; text-decoration: none; ">http://blog.csdn.net/aminfo/article/details/7872748</a></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>一、先上图片，这2张图片尺寸是一样的，放到drawable目录下：</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>图1：<span style="color: #3333ff; ">transparent.png</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><img alt="" src="http://my.csdn.net/uploads/201208/16/1345092248_3866.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>图2：<span style="color: #3333ff; ">transparent2.png</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><img alt="" src="http://my.csdn.net/uploads/201208/16/1345092258_4447.png" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>二、上布局文件，<span style="color: #000099; ">test.xml</span>：<br /><br /></strong><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">&lt;?</span><span style="color: #FF00FF; ">xml&nbsp;version="1.0"&nbsp;encoding="utf-8"</span><span style="color: #0000FF; ">?&gt;</span><br /><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">FrameLayout&nbsp;</span><span style="color: #FF0000; ">xmlns:android</span><span style="color: #0000FF; ">="http://schemas.android.com/apk/res/android"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;android:layout_width</span><span style="color: #0000FF; ">="fill_parent"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;android:layout_height</span><span style="color: #0000FF; ">="fill_parent"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;android:orientation</span><span style="color: #0000FF; ">="vertical"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;android:gravity</span><span style="color: #0000FF; ">="center"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;android:id</span><span style="color: #0000FF; ">="@+id/mainLayout"</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">ImageView&nbsp;</span><span style="color: #FF0000; ">android:id</span><span style="color: #0000FF; ">="@+id/ImageView01"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_width</span><span style="color: #0000FF; ">="wrap_content"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_height</span><span style="color: #0000FF; ">="wrap_content"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:src</span><span style="color: #0000FF; ">="@drawable/transparent"</span><span style="color: #0000FF; ">/&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">ImageView&nbsp;</span><span style="color: #FF0000; ">android:id</span><span style="color: #0000FF; ">="@+id/ImageView02"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_width</span><span style="color: #0000FF; ">="wrap_content"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_height</span><span style="color: #0000FF; ">="wrap_content"</span><span style="color: #FF0000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:src</span><span style="color: #0000FF; ">="@drawable/transparent2"</span><span style="color: #0000FF; ">/&gt;</span>&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">FrameLayout</span><span style="color: #0000FF; ">&gt;</span></div><strong><br /></strong><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->package&nbsp;org.shuxiang.test;<br /><br />import&nbsp;android.app.Activity;<br />import&nbsp;android.graphics.Bitmap;<br />import&nbsp;android.graphics.drawable.BitmapDrawable;<br />import&nbsp;android.os.Bundle;<br />import&nbsp;android.util.Log;<br />import&nbsp;android.view.MotionEvent;<br />import&nbsp;android.view.View;<br />import&nbsp;android.view.Window;<br />import&nbsp;android.view.View.OnClickListener;<br />import&nbsp;android.view.View.OnTouchListener;<br />import&nbsp;android.widget.ImageView;<br /><br />public&nbsp;class&nbsp;MainActivity&nbsp;extends&nbsp;Activity<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;ImageView&nbsp;iv1;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;ImageView&nbsp;iv2;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;Bitmap&nbsp;bitmap1,&nbsp;bitmap2;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;boolean&nbsp;iv1Transparent&nbsp;=&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;boolean&nbsp;iv2Transparent&nbsp;=&nbsp;false;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;onCreate(Bundle&nbsp;savedInstanceState)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;super.onCreate(savedInstanceState);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;requestWindowFeature(Window.FEATURE_NO_TITLE);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;setContentView(R.layout.test);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1&nbsp;=&nbsp;(ImageView)&nbsp;findViewById(R.id.ImageView01);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv2&nbsp;=&nbsp;(ImageView)&nbsp;findViewById(R.id.ImageView02);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap1&nbsp;=&nbsp;((BitmapDrawable)&nbsp;(iv1.getDrawable())).getBitmap();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bitmap2&nbsp;=&nbsp;((BitmapDrawable)&nbsp;(iv2.getDrawable())).getBitmap();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1.setOnClickListener(new&nbsp;OnClickListener(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;onClick(View&nbsp;v)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(iv1Transparent)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图1透明区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图1点击");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1.setOnTouchListener(new&nbsp;OnTouchListener()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;boolean&nbsp;onTouch(View&nbsp;arg0,&nbsp;MotionEvent&nbsp;arg1)&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(bitmap1.getPixel((int)(arg1.getX()),((int)arg1.getY()))==0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图1透明区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1Transparent&nbsp;=&nbsp;true;&nbsp;&nbsp;&nbsp;&nbsp;//透明区域设置true&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图1实体区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1Transparent&nbsp;=&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv2.setOnClickListener(new&nbsp;OnClickListener()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;void&nbsp;onClick(View&nbsp;v)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(iv2Transparent)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图2透明区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图2点击");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv2.setOnTouchListener(new&nbsp;OnTouchListener()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;boolean&nbsp;onTouch(View&nbsp;v,&nbsp;MotionEvent&nbsp;event)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;TODO&nbsp;Auto-generated&nbsp;method&nbsp;stub<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if(bitmap2.getPixel((int)(event.getX()),((int)event.getY()))==0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图2透明区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv2Transparent&nbsp;=&nbsp;true;&nbsp;&nbsp;&nbsp;&nbsp;//透明区域设置true<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv1.dispatchTouchEvent(event);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Log.i("test",&nbsp;"图2实体区域");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;iv2Transparent&nbsp;=&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;});<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><strong><br /><br /></strong></p><img src ="http://www.blogjava.net/hongqiang/aggbug/385634.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-16 22:28 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/16/385634.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> iOS开发——播放系统音效、自定义音效</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/16/385633.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Thu, 16 Aug 2012 14:26:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/16/385633.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385633.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/16/385633.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385633.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385633.html</trackback:ping><description><![CDATA[<div style="text-align: left; "><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; "><br />需求大致分为三种：</span></span></div><div style="text-align: left; "><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">1.震动</span></span></div><div style="text-align: left; "><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">2.系统音效（无需提供音频文件）</span></span></div><div style="text-align: left; "><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">3.自定义音效（需提供音频文件）</span></span></div><div style="text-align: left; "></div><div style="text-align: left; "></div><div style="text-align: left; "><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">我的工具类的封装：</span></span></div><div style="text-align: left; "><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><div bg_cpp"="" style="background-color: #ffffff; width: 685px; color: #333333; line-height: 25px; "><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="view plain">view plain</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="copy">copy</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="print">print</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="?">?</a><div style="position: absolute; left: 640px; top: 646px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;WQPlaySound.h&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;WQSound&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;Created&nbsp;by&nbsp;念茜&nbsp;on&nbsp;12-7-20.&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;Copyright&nbsp;(c)&nbsp;2012年&nbsp;__MyCompanyName__.&nbsp;All&nbsp;rights&nbsp;reserved.&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">#import&nbsp;&lt;UIKit/UIKit.h&gt;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">#import&nbsp;&lt;AudioToolbox/AudioToolbox.h&gt;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">@interface&nbsp;WQPlaySound&nbsp;:&nbsp;NSObject&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;SystemSoundID&nbsp;soundID;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">/**&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@brief&nbsp;&nbsp;为播放震动效果初始化&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@return&nbsp;self&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*/&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingVibrate;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">/**&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@brief&nbsp;&nbsp;为播放系统音效初始化(无需提供音频文件)&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@param&nbsp;resourceName&nbsp;系统音效名称&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@param&nbsp;type&nbsp;系统音效类型&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@return&nbsp;self&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*/&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingSystemSoundEffectWith:(NSString&nbsp;*)resourceName&nbsp;ofType:(NSString&nbsp;*)type;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">/**&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@brief&nbsp;&nbsp;为播放特定的音频文件初始化（需提供音频文件）&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@param&nbsp;filename&nbsp;音频文件名（加在工程中）&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@return&nbsp;self&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*/&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingSoundEffectWith:(NSString&nbsp;*)filename;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">/**&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*&nbsp;&nbsp;@brief&nbsp;&nbsp;播放音效&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;*/&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(void)play;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">@end&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "><br /></p><div bg_cpp"="" style="background-color: #ffffff; width: 685px; color: #333333; line-height: 25px; "><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="view plain">view plain</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="copy">copy</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="print">print</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="?">?</a><div style="position: absolute; left: 640px; top: 1717px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_2" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_2" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;WQPlaySound.m&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;WQSound&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;Created&nbsp;by&nbsp;念茜&nbsp;on&nbsp;12-7-20.&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;Copyright&nbsp;(c)&nbsp;2012年&nbsp;__MyCompanyName__.&nbsp;All&nbsp;rights&nbsp;reserved.&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">//&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">#import&nbsp;"WQPlaySound.h"&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">@implementation&nbsp;WQPlaySound&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingVibrate&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;self&nbsp;=&nbsp;[super&nbsp;init];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(self)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soundID&nbsp;=&nbsp;kSystemSoundID_Vibrate;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;self;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingSystemSoundEffectWith:(NSString&nbsp;*)resourceName&nbsp;ofType:(NSString&nbsp;*)type&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;self&nbsp;=&nbsp;[super&nbsp;init];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(self)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSString&nbsp;*path&nbsp;=&nbsp;[[NSBundle&nbsp;bundleWithIdentifier:@"com.apple.UIKit"]&nbsp;pathForResource:resourceName&nbsp;ofType:type];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(path)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SystemSoundID&nbsp;theSoundID;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OSStatus&nbsp;error&nbsp;=&nbsp;&nbsp;AudioServicesCreateSystemSoundID((__bridge&nbsp;CFURLRef)[NSURL&nbsp;fileURLWithPath:path],&nbsp;&amp;theSoundID);&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(error&nbsp;==&nbsp;kAudioServicesNoError)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soundID&nbsp;=&nbsp;theSoundID;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"Failed&nbsp;to&nbsp;create&nbsp;sound&nbsp;");&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;self;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(id)initForPlayingSoundEffectWith:(NSString&nbsp;*)filename&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;self&nbsp;=&nbsp;[super&nbsp;init];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(self)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSURL&nbsp;*fileURL&nbsp;=&nbsp;[[NSBundle&nbsp;mainBundle]&nbsp;URLForResource:filename&nbsp;withExtension:nil];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(fileURL&nbsp;!=&nbsp;nil)&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SystemSoundID&nbsp;theSoundID;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OSStatus&nbsp;error&nbsp;=&nbsp;AudioServicesCreateSystemSoundID((__bridge&nbsp;CFURLRef)fileURL,&nbsp;&amp;theSoundID);&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(error&nbsp;==&nbsp;kAudioServicesNoError){&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;soundID&nbsp;=&nbsp;theSoundID;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}else&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NSLog(@"Failed&nbsp;to&nbsp;create&nbsp;sound&nbsp;");&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;self;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(void)play&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;AudioServicesPlaySystemSound(soundID);&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">-(void)dealloc&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">{&nbsp;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">&nbsp;&nbsp;&nbsp;&nbsp;AudioServicesDisposeSystemSoundID(soundID);&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">@end&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "><br /></p><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "><span style="font-size: 18px; "><span style="font-family: 'Comic Sans MS'; ">调用方法步骤：<br /></span><span style="font-family: 'Comic Sans MS'; ">1.加入AudioToolbox.framework到工程中<br /></span><span style="font-family: 'Comic Sans MS'; ">2.调用WQPlaySound工具类<br /></span></span></p><h3><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">2.1震动</span></span></h3><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><div bg_cpp"="" style="background-color: #ffffff; width: 685px; color: #333333; line-height: 25px; "><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="view plain">view plain</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="copy">copy</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="print">print</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="?">?</a><div style="position: absolute; left: 640px; top: 3376px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_3" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_3" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; ">WQPlaySound&nbsp;*sound&nbsp;=&nbsp;[[WQPlaySound&nbsp;alloc]initForPlayingVibrate];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">[sound&nbsp;play];&nbsp;&nbsp;</li></ol></div><br style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; " /><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><h3><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">2.2系统音效，以Tock为例</span></span></h3><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><div bg_cpp"="" style="background-color: #ffffff; width: 685px; color: #333333; line-height: 25px; "><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="view plain">view plain</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="copy">copy</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="print">print</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="?">?</a><div style="position: absolute; left: 640px; top: 3546px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_4" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_4" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; ">WQPlaySound&nbsp;*sound&nbsp;=&nbsp;[[WQPlaySound&nbsp;alloc]initForPlayingSystemSoundEffectWith:@"Tock"&nbsp;ofType:@"aiff"];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">[sound&nbsp;play];&nbsp;&nbsp;</li></ol></div><br style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; " /><h3><span style="font-family: 'Comic Sans MS'; "><span style="font-size: 18px; ">2.3自定义音效，将tap.aif音频文件加入到工程</span></span></h3><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><div bg_cpp"="" style="background-color: #ffffff; width: 685px; color: #333333; line-height: 25px; "><div><div><strong>[cpp]</strong>&nbsp;<a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="view plain">view plain</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="copy">copy</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="print">print</a><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7870328#" title="?">?</a><div style="position: absolute; left: 640px; top: 3722px; width: 32px; height: 15px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_5" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="32" height="15" name="ZeroClipboardMovie_5" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&amp;width=32&amp;height=15" wmode="transparent" style="-webkit-animation-duration: 0.001s; -webkit-animation-name: nodeInserted; "></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 20px; ">WQPlaySound&nbsp;*sound&nbsp;=&nbsp;[[WQPlaySound&nbsp;alloc]initForPlayingSoundEffectWith:@"tap.aif"];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 20px; ">[sound&nbsp;play];&nbsp;&nbsp;</li></ol></div><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "></p><p style="color: #333333; font-family: Arial; line-height: 25px; background-color: #ffffff; "><a href="http://download.csdn.net/detail/yiyaaixuexi/4502321" target="_blank" style="color: #336699; text-decoration: none; ">tap.aif音频文件样例下载点击</a><span style="font-family: 'Comic Sans MS'; "><br /></span></p></div><img src ="http://www.blogjava.net/hongqiang/aggbug/385633.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-16 22:26 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/16/385633.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>UML建模之状态图</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/08/385092.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 08 Aug 2012 15:38:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/08/385092.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385092.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/08/385092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385092.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385092.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 24px; ">&nbsp;状态图主要描述一个对象在其生命周期内的状态变化，对象由事件驱动并满足一定的条件从一个状态转换到另一个状态。状态图显示了一个状态机。</span></p><div style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 24px; "><br /></span></div><div style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 24px; ">下面是一个表示借书的状态图（描述书的状态转换）</span></div><div style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387460_3148.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/3BF2EB7F76E245A08A76C964608A30FE/CC162FE3092C436FBE970F1104A4D7D9.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /><br /></span><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">状态图都由哪些元素组成呢？</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">一、初始状态</span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387479_1290.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/AFBBCD485E6D4AA587614825ECAADF12/63C14BB6105846E2883C280CA9C8AC05.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; ">&nbsp; &nbsp; &nbsp; 初始状态是状态机的起始位置，它不需要事件的触发。<span style="color: #ff0000; ">一个状态图只能有一个初始状态。</span>状态图总是以初始状态开始，以终止状态结束</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">二、状态</span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387497_7162.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/4DCA8FB634804BF7950D8D3D7AFEB186/E39B1178B2D14F85A7E7759976882755.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">状态是对象执行某项活动或等待某个事件时的条件。状态可以由以下几部分组成：</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">1、Name：状态名称</span></div><div><span style="font-size: 24px; ">2、Entry/Exit Action：进入和退出动作</span></div><div><span style="font-size: 24px; ">3、Internal Transition：内部转移（对事件作出响应，执行一定的动作，但不会发生状态的转换）</span></div><div><span style="font-size: 24px; ">4、Do：状态保持不变时执行的动作</span></div><div><span style="font-size: 24px; ">5、SubStage：子状态（当状态是复合状态时）</span></div><div><span style="font-size: 24px; ">6、Deferred Event：延迟事件（未在本状态中处理，但不被丢弃，而是延迟到其它状态中处理的事件）</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">下面是一个灯的点燃状态的例子</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/03FFB9FC47B14076BF2DDCE69B2B1EA6/C36D9968B9174162BBC4817963351244.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387519_2040.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; ">&nbsp; &nbsp; &nbsp; &nbsp;如果一个状态比较复杂，那么它还可以拥有子状态，拿上面借书的例子，书的被借状态又可包含两个子状态：被正常借、被续借</span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387540_3148.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/59704D85129C401EBFE12D465E856365/D4374242BF2F4FFA861A42EBC1A608BC.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">三、转移</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">&nbsp; &nbsp; &nbsp; 上面已经讲过了一种特殊的转移：内部转移，但是这种转移只是响应一定的事件，执行一定的动作，并不会放生状态的转移</span></div><div><span style="font-size: 24px; ">下面介绍一下一般转移的格式：</span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387569_5558.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/88A9FECC8FB9461C994AB953949B386C/9966613090CA4E49BB16B3C920A965FB.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; ">状态的转移一般由三部分组成</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">1、event（事件）：触发状态转移的原因</span></div><div><span style="font-size: 24px; ">2、Guard Condition（保卫条件）：是一个布尔表达式，当事件被触发时要判断保卫条件的值，值为True才会发生状态的转换</span></div><div><span style="font-size: 24px; ">3、Action（活动）：状态转换时执行的活动</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">下面是一个电水壶烧水的状态转换</span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387593_3306.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/3CAF1B81DBDB4EC8990ABBBEC0427E21/D1519DB4D447483BA5ADC88B60AE0180.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; ">&nbsp; &nbsp; &nbsp; &nbsp;当事件turn on放生时，只有水壶内有水（have water）才能由off状态转换到on状态，并发生烧水的动作（Boiling Water）。其实动作也可以放在on状态中。</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; ">四、结束状态</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="http://my.csdn.net/uploads/201208/08/1344387617_2379.png" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; " /><br /></span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><img src="file:///C:/Users/WH/AppData/Local/youdao/ynote/images/D820AA30454E4FD79E3CB3756853883B/6E6D7A660F6E470096A3671306F87D5D.jpg" alt="" style="border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; display: inline-block; " /></span></div><div><span style="font-size: 24px; ">结束状态表示状态机执行结束或对象生命的终结，<span style="color: #ff0000; ">一个状态图可以有多个结束状态</span>。</span></div><div><span style="font-size: 24px; "><br /></span></div><div><span style="font-size: 24px; "><br style="font-family: 微软雅黑; " /></span><div><span style="font-size: 24px; "><span style="font-family: 微软雅黑; ">&nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-family: SimSun; ">在实际的应用中，不必为每个对象都创建状态图，而是只为那些比较复杂的，状态比较多的对象创建状态图。状态图是一种很有用的图，它可以帮助我们分析复杂对象的状态转换和对象在什么时候执行什么样的动作。网上购物过程中，我们会经常查看订单的状态，描述订单的状态机就是一个比较经典的状态图，网上有很多关于订单状态图的例子，大家可以查一下，我在这里就不再赘述了。</span></span></div></div></div><img src ="http://www.blogjava.net/hongqiang/aggbug/385092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-08 23:38 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/08/385092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>《时间管理》课程笔记（一）</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/08/385093.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 08 Aug 2012 15:38:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/08/385093.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385093.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/08/385093.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385093.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385093.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">1. 为什么要时间管理&nbsp;&nbsp;&nbsp; 曾经有过这样一个报道：有一名记者随机采访了几个人，问了这样一个问题：<br />&nbsp;&nbsp;&nbsp; 你认为你的时间是由自己来掌控的吗？得到的回答却是这样的：<br />&nbsp;&nbsp;&nbsp; 如今各种竞争如此激烈，能拉到一个客户不容易，只要客户一个电话，我就马上要出现，我的时间完全由客户掌控。<br />&nbsp;&nbsp;&nbsp; 我只不过是一名普通的小职员，主管给我安排什么我就做什么。自己掌控时间？！等我当了经理再说吧。<br />&nbsp;&nbsp;&nbsp; 我总是有忙不完的工作，哪还来得及自己安排时间？别开玩笑了。<br />&nbsp;&nbsp;&nbsp; 在这样一个信息爆炸的社会里，我不抓紧时间充电就会落后了，现在是时间在控制我啊！<br />&nbsp;&nbsp;&nbsp; 相信你对这个问题会有自己的见解，但是仔细想想你的答案是否跟他们的很类似呢？像他们一样，也有这样的困惑或是感受呢？之所以有这样的困惑，有一个最主要的因素在影响着我们，这个因素是什么呢？<br />&nbsp;&nbsp;&nbsp; 职位？竞争？时间？<br />&nbsp;&nbsp;&nbsp; 每个人的时间总是不够用，人们渴望找到一种灵丹妙药，彻底改变自己时间不够用的局面。你是否也是这里的一员呢？</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">2. 概述&nbsp;&nbsp;&nbsp; 时间是一种资源，我们无法对它进行买卖，不可能与别人分享或是从别人那里获得，也不可能得到更多或是拥有更少。<br />&nbsp;&nbsp;&nbsp; 每天，我们每一个人都拥有相同数量的时间&#8212;&#8212;24小时，差别在于我们用它来做什么。之所以每个人会有种种的困惑，究其原因，是因为大多数人在时间的管理上存在着很多误区，只有消除这些误区，才有可能让我们把时间管理得更好、更有效。<br />&nbsp;&nbsp;&nbsp; 我们现在就一起去看看这些误区都是什么样的吧！</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">3. 误区展示&nbsp;&nbsp;&nbsp; 当你的工作中出现问题时，你认为是什么原因造成的？<br />&nbsp;&nbsp;&nbsp; 无论，你的实际情况是怎么样的，往往我们都忽略了一个最关键的问题，那就是&#8220;时间&#8221;。<br />&nbsp;&nbsp;&nbsp; 因为时间的不充足而没来得及做这个或是做那个，导致最后的结果总是不尽如人意。所以，每个人在时间管理上都或多或少存在一定的问题，这也是接下来我们要解决的问题。请点击下一页吧。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">4. 反思&nbsp;&nbsp;&nbsp; 这个世界上根本不存在&#8220;没时间&#8221;这回事。<br />&nbsp;&nbsp;&nbsp; 如果你跟很多人一样，也是因为&#8220;太忙&#8221;而没时间完成自己的工作的话，那请你一定记住，在这个世界上还有很多人，他们比你更忙，结果却完成了更多的工作。这些人并没有比你拥有更多的时间，他们只是学会了如何更好地利用自己的时间而已！有效的利用时间是一种人人都可以掌握的技巧&#8212;&#8212;就像开车一样。<br />&nbsp;&nbsp;&nbsp; 因此，希望大家能通过这门课程的学习，在今后的生活中有效的珍惜时间，而一旦把握好时间，你就掌握了自己的生命，并能够将其价值发挥到极限。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">5. 时间管理课程概述&nbsp;&nbsp;&nbsp; 在本课程中，将通过四个方面的内容帮助你更好的掌握自己的时间，而不是成为时间的奴隶，从而让你实现自己的人生目标。<br />&nbsp;&nbsp;&nbsp; 首先，我们要谈谈人生目标，也就是我们花了时间都做了些什么，比如你想成为什么样的人，你将来要达到一种什么样的成就等。<br />&nbsp;&nbsp;&nbsp; 第二、当你有了明确的人生目标，那该用什么方法来实现呢，也就是接下来要讲的时间管理的核心思想&#8220;时间管理矩阵&#8221;等。<br />&nbsp;&nbsp;&nbsp; 第三、了解了如何管理时间，那么接下来要介绍的是怎么来自我管理。如何利用好每一天的时间来帮助我们实现人生的大目标。<br />&nbsp;&nbsp;&nbsp; 最后，就是学会利用工具来管理时间。<br />&nbsp;&nbsp;&nbsp; 总而言之，对于你来说，这个世界上没有任何东西比时间更加重要了。每个人的时间都是相同的，我们每个人每个星期都只有168个小时，不可能有更多的时间。<br />&nbsp;&nbsp;&nbsp; 这门课程可以帮助你更有效的利用这些时间。<br />&nbsp;&nbsp;&nbsp; 让我们开始吧！</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">6. 概述&nbsp;&nbsp;&nbsp; 时间我们无法随意的让它变大或是缩小，我们也不能像存钱一样把时间储备起来，以备不时之需；更不能用其它的东西来代替，甚至我们更不能把已经失去的时间像倒带子一样，有选择性的倒回来或是快放。<br />&nbsp;&nbsp;&nbsp; 因此，当人们无所事事，或者忙得晕头转向却不见成效时，应该暂时停下来审视一下自己的时间利用效率，审视一下自己在时间中所处的角色，寻找一条更为合适的途径，实现自己的目标，追求自己的人生价值。<br />&nbsp;&nbsp;&nbsp; 在经理人的所有管理技能中，时间管理最容易被忽略。初级经理人从员工的岗位过渡到管理者的岗位，比较容易忽略管理的角色和时间管理的技能，而中、高级管理者的工作时间更忙碌，工作任务更多，时间效率的管理也就显得更加重要。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">7. 案例&nbsp;&nbsp;&nbsp; 假设一个人的生命中有三枚硬币，第一枚代表财富，第二枚代表健康，第三枚代表时间，请问哪一个更重要？<br />&nbsp;&nbsp;&nbsp; 无论你选择了什么，我们来逐一分析一下吧。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">8. 分析一&nbsp;&nbsp;&nbsp; 这三枚硬币哪个更重要呢？<br />&nbsp;&nbsp;&nbsp; 第一种情况：<br />&nbsp;&nbsp;&nbsp; 通常人们都趋向于追求财富，如果在这三枚硬币中，把代表财富的硬币拿掉，则表示这个人有足够多的健康，也有足够多的时间，他有可能重新去创业，赢得财富，把代表财富的硬币重新放进自己的生命中。<br />&nbsp;&nbsp;&nbsp; 你赞成这个说法吗？<br />&nbsp;&nbsp;&nbsp; 赞成&nbsp;&nbsp;&nbsp; 不赞成<br />&nbsp;&nbsp;&nbsp; 无论你选择了什么，我们来看一个实例：<br />&nbsp;&nbsp;&nbsp; 房地产大亨李嘉诚，相信你一定听说过吧！<br />&nbsp;&nbsp;&nbsp; 17岁独自外出闯荡，经商60多年，建立起亚洲最大的商业王国。&nbsp;<br />&nbsp;&nbsp;&nbsp; 李嘉诚现在年过八旬仍然精神矍铄，思维敏捷。他说：&#8220;健康就好似堤坝一样，如果快要崩堤了再做补救，花费多少人力物力可能救不回来。&#8221;<br />&nbsp;&nbsp;&nbsp; 问到成功秘诀时，李嘉诚认为惜时如金，是他的一个成功秘诀，李嘉诚每天清晨不到6点就起床了，中午不睡午觉，晚上睡觉前还要看书。<br />&nbsp;&nbsp;&nbsp; 李嘉诚认为：在商业竞争中，你输了，那么你输在时间；反之，你赢了，也赢在时间。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">9. 分析二&nbsp;&nbsp;&nbsp; 第二种情况：<br />&nbsp;&nbsp;&nbsp; 如果在这三枚硬币中，把代表健康的硬币拿掉，这表示这个人有足够多的财富，也有足够多的时间，则他可以花费无以计数的金钱来治疗自己的疾病，至少可以拖延一定的时间，或借助高科技手段来延长生命，他可能把代表健康的硬币重新放进自己的生命中。<br />&nbsp;&nbsp;&nbsp; 你赞成这个说法吗？<br />&nbsp;&nbsp;&nbsp; 赞成&nbsp;&nbsp;&nbsp; 不赞成<br />&nbsp;&nbsp;&nbsp; 我想梅艳芳大家都听说过吧？<br />&nbsp;&nbsp;&nbsp; 梅艳芳患癌后，每周必须接受5天的治疗，光是每个月的医药费就高达港币80万，一年下来要花近千万港币。她可以用财富延长自己的生命，并用这些有限的生命完成自己最后的心愿，但是健康依然离她很遥远。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">10. 分析三&nbsp;&nbsp;&nbsp; 第三种情况：<br />&nbsp;&nbsp;&nbsp; 如果把代表时间的硬币拿走，让一个人没有自己的时间了，这时候，即使他有无数的财富，有很强壮的身体，可是生命留给他的只有一刹那，他无法用1亿美元去换10分钟，这就好比无数的0前面没有了1，是没有任何意义的，他不仅不能将代表时间的硬币重新放进自己的人生，而且财富和健康对他也变得毫无意义了。<br />&nbsp;&nbsp;&nbsp; 你赞成这个说法吗？<br />&nbsp;&nbsp;&nbsp; 赞成&nbsp;&nbsp;&nbsp; 不赞成<br />&nbsp;&nbsp;&nbsp; 无论你选择的是什么，时间对我们确实很重要。<br />&nbsp;&nbsp;&nbsp; 大家都知道，秦始皇是第一位统一六国并实现了文化及货币统一的皇帝。<br />&nbsp;&nbsp;&nbsp; 他为了让自己永远稳坐江山，就派人去寻找长生不老药。他非常清楚时间就是生命，如果自己能永生就等于掌握了时间并永远稳坐江山。<br />&nbsp;&nbsp;&nbsp; 最终，还是以失败告终。即便他有再多的财富与健康的体魄，他依然无法实现永生的愿望。因为时间不会根据任何人的愿望而改变。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">11. 总结&nbsp;&nbsp;&nbsp; 总之，对于所有的人，尤其是经理人、企业家，他们有大量的金钱，可是他们感到最缺的还是时间，所以对时间的要求就更高，这就需要良好的时间管理。时间管理就是有效地应用时间这种资源以便我们有效地取得个人的重要目标。<br />&nbsp;&nbsp;&nbsp; 接下来，就让我们一起来学习有关个人目标的内容吧。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">12. 自我时间状态判断&nbsp;&nbsp;&nbsp; 学习了时间管理的重要性和概念，现在我们一起应用这些知识来分析一下你自己吧！</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">13. 拖延商数测试&nbsp;&nbsp;&nbsp; 在回答这些问题时，一方面是为了让你重新认识一下自己，另一方面这些可能也是你浪费时间的原因。<br />&nbsp;&nbsp;&nbsp; 现在请做一个测试，看看你做事的拖延情况究竟如何吧。<br />&nbsp;&nbsp;&nbsp; 你的拖延情况严重吗？<br />&nbsp;&nbsp;&nbsp; 做事拖延，会严重浪费你的时间，一起来看看浪费时间的因素具体是哪些吧。时间盗贼：(找东西、懒惰，时断时续，一个人包打天下，偶发延误，惋惜不已/做白日梦，拖拖拉拉，对问题缺乏理解就匆忙行动，消极情绪，分不清轻重缓急)</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">14. 小结&nbsp;&nbsp;&nbsp; 至此，我们已经了解了时间管理的误区有哪些，以及时间管理的定义、必要性，同时通过测试对自己有了新的认识。<br />&nbsp;&nbsp;&nbsp; 如果你确认对上述内容已经完全掌握，就请开始下一章的学习吧！</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">15. 概述　　你有人生目标吗？请你试着回答下面的问题：<br />　　你现在是把时间真正用在你想做的事情上了吗？<br />　　你是在&#8220;原地踏步&#8221;吗？<br />　　你正在左右为难&#8212;&#8212;是前进还是放慢脚步，或者正在犹豫不决？<br />　　如果你不能把时间用来去实现你认为最重要的目标的话，那么你就要对其进行调整。现在请点击下一页让我来帮助你一起回答以上这些问题吧。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">16. 为什么需要目标&nbsp;&nbsp;&nbsp; 为什么要设定人生目标呢？<br />&nbsp;&nbsp;&nbsp; 许多人拼命埋头苦干，却不知所为何来，到头来却发现追求的梯子搭错了墙，懊悔不已，只可惜为时已晚，之所以有的人总是很忙碌，而做的事情却没有太大意义，就是因为他们没有一个明确的目标。<br />&nbsp;&nbsp;&nbsp; 你现在处于最理想的状态吗？<br />&nbsp;&nbsp;&nbsp; 最理想的状态是指，你所做的每件事对你都是有价值的&#8212;&#8212;其价值在于它积极推动你实现职业上的或是个人生活上的目标&#8212;&#8212;这些事情都是你希望可以完成的。没有其他人可以替你做决定，你必须得明确什么事情对于你来说才是最重要的。<br />&nbsp;&nbsp;&nbsp; 需要注意的是，实现目标，需要一个过程。而在过程中的每一个阶段，都会有一个阶段性目标，越往后发展，阶段性目标就越接近最终目标。正是通过每一个阶段性目标的成功实现，才能实现最终目标。因此，目标永远指明了前进的方向。<br />&nbsp;&nbsp;&nbsp; 现在你明白为什么需要目标了吗？<br />&nbsp;&nbsp;&nbsp; 请继续学习后面的内容吧。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">17. 人生目标序言&nbsp;&nbsp;&nbsp; 大人们总喜欢问自己的孩子：你长大了想做什么啊？<br />&nbsp;&nbsp;&nbsp; 小孩子会毫不犹豫的说：<br />&nbsp;&nbsp;&nbsp; &#8220;我要像爸爸一样，当一名建筑工程师&#8230;&#8230;&#8221;<br />&nbsp;&nbsp;&nbsp; &#8220;我要当一名科学家或是一名作家&#8230;&#8230;&#8221;<br />&nbsp;&nbsp;&nbsp; &#8220;我要像妈妈一样，当一名医生&#8230;&#8230;&#8221;<br />&nbsp;&nbsp;&nbsp; &#8220;我要当一名警察或者天文学家&#8230;&#8230;&#8221;<br />&nbsp;&nbsp;&nbsp; &#8220;我要当一名宇航员，飞上太空&#8230;&#8230;&#8221;<br />&nbsp;&nbsp;&nbsp;&nbsp; &#8230;&#8230; &#8230;&#8230; &#8230;&#8230;<br />&nbsp;&nbsp;&nbsp; 各种各样的回答，都代表了孩子的一个人生目标。<br />&nbsp;&nbsp;&nbsp; 你认为这些目标可以更改吗？<br />&nbsp;&nbsp;&nbsp; 无论你的目标是否发生变化，时间都会一分一秒的过去，这是一个不变的规律。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">18. 要明确人生目标&nbsp;&nbsp;&nbsp; 为了加深你对目标的理解，一起来看看这样一组调查数据。<br />&nbsp;&nbsp;&nbsp; 表中列出了某一年哈佛大学400名学生及他们毕业后25年的调查数据。那些没有目标的人，结果是生活在社会的底层，而那些目标明确的人，都生活在社会的中上层。令人深思的是，这些人的起点几乎是一样的，然而，正是因为目标这一因素导致了巨大的结果差异。可见，目标对人生的影响是多么的巨大。<br />&nbsp;&nbsp;&nbsp; 到这里，我想问你一个问题，你有长期或者短期的目标吗？<br />&nbsp;&nbsp;&nbsp; 有没有不重要，希望从这一刻开始，你要为自己设定明确且合理的长期与短期目标。<br />&nbsp;&nbsp;&nbsp; 现在，请写出你的人生目标：<br />&nbsp;&nbsp;&nbsp; 请拿出几张纸，一支铅笔或钢笔，一只带有秒针的手表或时钟，为自己设定15分钟时间。在纸的最上端写下问题。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">19. 你的人生目标到底是什么？&nbsp;&nbsp;&nbsp; 第一个问题：<br />&nbsp;&nbsp;&nbsp; 你的人生目标到底是什么？<br />&nbsp;&nbsp;&nbsp; 用第一人称、现在时、肯定语气来写，这样，这些目标就能立即进入你的潜意识中。<br />&nbsp;&nbsp;&nbsp; 不要害怕写出那些看起来距离自己很遥远的目标。这些目标可以是有形的或是无形的。<br />&nbsp;&nbsp;&nbsp; 比如说登上珠穆朗玛峰、去参加马拉松长跑、休假一年、退休后在意大利建一座房子、买艘游艇、购买一辆宝马轿车；拥有一个美满幸福的三口之家，自己能拥有一个健康的身体&#8230;&#8230;这些都可以列出来，同时请列出优先顺序。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">20. 如何度过今后三年&nbsp;&nbsp;&nbsp; 第二个问题：<br />&nbsp;&nbsp;&nbsp; 如何度过今后三年？<br />&nbsp;&nbsp;&nbsp; 三年的时间，看似很长，那么在这么长的时间里你能做些什么呢？<br />&nbsp;&nbsp;&nbsp; 你可以写下一些比较空泛的目标，比如说&#8220;获得幸福&#8221;、&#8220;取得成功&#8221;、&#8220;赢得爱情&#8221;、&#8220;为社会做贡献&#8221;、&#8220;读完30本书&#8221;、&#8220;游遍30个国家&#8221;等等。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">21. 只能活六个月你该怎样渡过&nbsp;&nbsp;&nbsp; 第三个问题：<br />&nbsp;&nbsp;&nbsp; 只能活六个月怎样度过？<br />&nbsp;&nbsp;&nbsp; 如果你知道自己会在六个月后因为病魔的侵入而失去生命，你会怎样度过这六个月的时间？你可以从不同的角度去想。<br />&nbsp;&nbsp;&nbsp; 请注意：这意味着你的人生只剩下六个月的时间，你必须充分利用这段时间做一些你觉得最重要或者自己一直都想做而没做的事情。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">22. 三个问题之间的思考&nbsp;&nbsp;&nbsp; 你可以花上至少两分钟的时间，仔细斟酌并修改你对以上三个问题的回答。如果愿意，你也可以花上更多的时间。<br />&nbsp;&nbsp;&nbsp; 同时，请你认真思考一下这三个问题之间的关系是怎样的？<br />&nbsp;&nbsp;&nbsp; 现在我们来分析一下这三个问题：第一个可以看作是长期目标、第二个是短期目标、第三个是被分解后的目标。<br />&nbsp;&nbsp;&nbsp; 你可能会发现第二个问题的答案其实是第一个问题答案的延伸，还有一些人发现自己在第三个问题上的答案跟前两个问题的答案截然不同&#8212;&#8212;那是因为他们突然意识到自己的时间不多了，必须在有限的时间内完成最重要、最紧急的事情。</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="font-family: FangSong_GB2312; font-size: 18px; ">23. 如何设定人生目标&nbsp;&nbsp;&nbsp; 了解为什么设定人生目标后，现在我们就来学习一下如何设定人生目标吧。<br />&nbsp;&nbsp;&nbsp; 事实上，设定一个适当的目标就等于达到了目标的一部分。<br />&nbsp;&nbsp;&nbsp; 人生的大目标也是人生大志，可能需要十年、二十年甚至终生为之奋斗。一个人不可能一口吃成一个胖子，所以我们在追求人生目标的过程中，要时刻清楚自己现在做的每一件事都要有助于实现自己最终的目标。<br />&nbsp;&nbsp;&nbsp; 接下来，我们就详细讲解一下如何有效地设定人生目标。</span></p><img src ="http://www.blogjava.net/hongqiang/aggbug/385093.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-08 23:38 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/08/385093.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>单例设计模式中使用dom4j来完成(数据库配置文件)xml的解析，并完成数据库的连接</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/08/385091.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 08 Aug 2012 15:37:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/08/385091.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385091.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/08/385091.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385091.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385091.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>本文主要简述的内容有单例设计模式、dom4j解析xml文件（这里解析的数据库的配置文件）、通过解析出来的配置信息完成数据库的连接。</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong><span style="color: #ff0000; ">1、首先要看的是单例设计模式</span></strong><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 单例设计模式的实现有两种：饿汉式（预先加载）、懒汉式（延迟加载），下面分别来看这两种实现方式。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">（1）、饿汉式（预先加载）<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Singleton{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;Singleton&nbsp;instance&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Singleton();<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;Singleton(){}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">synchronized</span>&nbsp;Singleton&nbsp;getInstance(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;instance;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />}</div>（2）懒汉式（延迟加载）&nbsp;<br /><br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;Singleton{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;Singleton&nbsp;instance&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;Singleton(){}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">synchronized</span>&nbsp;Singleton&nbsp;getInstance(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(instance==<span style="color: #0000FF; ">null</span>){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;Singleton();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;instance;<br />&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<br />}</div><br />观察上面的这两种模式，看起来区别并不大，前一种方式是类一旦加载就得将对象实例化了，而后一种则是在使用的时候才进行判断是否要实例化对象，并且在后一种的getInstance方法中加入了同步，这样显得更加的合理，个人更加偏好于使用第二种方式。<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong><span style="color: #ff0000; ">2、使用dom4j来完成数据库配置文件的解析</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">给出下面这个数据库的配置文件<strong>sys-config.xml</strong></p><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">&lt;?</span><span style="color: #FF00FF; ">xml&nbsp;version="1.0"&nbsp;encoding="UTF-8"</span><span style="color: #0000FF; ">?&gt;</span><br /><span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">config</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">db-info</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">driver</span><span style="color: #0000FF; ">&gt;</span>oracle.jdbc.driver.OracleDriver<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">driver</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">url</span><span style="color: #0000FF; ">&gt;</span>jdbc:oracle:thin:@127.0.0.1:1521:ORCL<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">url</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">user</span><span style="color: #0000FF; ">&gt;</span>username<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">user</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;</span><span style="color: #800000; ">password</span><span style="color: #0000FF; ">&gt;</span>password<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">password</span><span style="color: #0000FF; ">&gt;</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">db-info</span><span style="color: #0000FF; ">&gt;</span><br /><span style="color: #0000FF; ">&lt;/</span><span style="color: #800000; ">config</span><span style="color: #0000FF; ">&gt;</span></div><br />完成解析的java类：<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">（1）、保存数据库jdbc配置信息的模型类<strong>JdbcConfig.java</strong></p><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span>&nbsp;org.ml.drp.util;<br /><br /><span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;*&nbsp;用于保存数据库连接时的jdbc参数<br />&nbsp;*&nbsp;<br />&nbsp;*&nbsp;</span><span style="color: #808080; ">@author</span><span style="color: #008000; ">&nbsp;MuLing<br />&nbsp;*&nbsp;<br />&nbsp;</span><span style="color: #008000; ">*/</span><br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;JdbcConfig&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;DbDriver;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;DbUrl;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;DbUser;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;String&nbsp;DbPass;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getDbDriver()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;DbDriver;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setDbDriver(String&nbsp;dbDriver)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbDriver&nbsp;=&nbsp;dbDriver;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getDbUrl()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;DbUrl;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setDbUrl(String&nbsp;dbUrl)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbUrl&nbsp;=&nbsp;dbUrl;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getDbUser()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;DbUser;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setDbUser(String&nbsp;dbUser)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbUser&nbsp;=&nbsp;dbUser;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;getDbPass()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;DbPass;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;setDbPass(String&nbsp;dbPass)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DbPass&nbsp;=&nbsp;dbPass;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;@Override<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;String&nbsp;toString()&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;"JdbcConfig&nbsp;[DbDriver="&nbsp;+&nbsp;DbDriver&nbsp;+&nbsp;",&nbsp;DbUrl="&nbsp;+&nbsp;DbUrl<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;",&nbsp;DbUser="&nbsp;+&nbsp;DbUser&nbsp;+&nbsp;",&nbsp;DbPass="&nbsp;+&nbsp;DbPass&nbsp;+&nbsp;"]";<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><br />（2）、解析数据库配置文件的工具类<strong>XmlConfigReader.java</strong>,这里使用单例模式完成，采用的是懒汉式。&nbsp;<br /><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span>&nbsp;org.ml.drp.util;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;java.io.InputStream;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;org.dom4j.Document;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.dom4j.DocumentException;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.dom4j.Element;<br /><span style="color: #0000FF; ">import</span>&nbsp;org.dom4j.io.SAXReader;<br /><span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;*&nbsp;用于解析xml文件&nbsp;<br />&nbsp;*&nbsp;</span><span style="color: #808080; ">@author</span><span style="color: #008000; ">&nbsp;MuLing<br />&nbsp;*<br />&nbsp;</span><span style="color: #008000; ">*/</span><br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;XmlConfigReader&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;JdbcConfig&nbsp;jdbcConfig&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;XmlConfigReader&nbsp;instance&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">private</span>&nbsp;XmlConfigReader(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SAXReader&nbsp;reader&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;SAXReader();<span style="color: #008000; ">//</span><span style="color: #008000; ">取得SAXReader的对象</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;InputStream&nbsp;input&nbsp;=&nbsp;Thread.currentThread().getContextClassLoader().getResourceAsStream("sys-config.xml");<span style="color: #008000; ">//</span><span style="color: #008000; ">得到输入流对象</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbcConfig&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;JdbcConfig();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Document&nbsp;doc&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">try</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;doc&nbsp;=&nbsp;reader.read(input);&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">进行读取</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(DocumentException&nbsp;e)&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">取得对应的节点对象</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;nbsp;Element&nbsp;driverEle&nbsp;=&nbsp;(Element)doc.selectObject("/config/db-info/driver");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;urlEle&nbsp;=&nbsp;(Element)doc.selectObject("/config/db-info/url");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;userEle&nbsp;=&nbsp;(Element)doc.selectObject("/config/db-info/user");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Element&nbsp;passwordEle&nbsp;=&nbsp;(Element)doc.selectObject("/config/db-info/password");&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbcConfig.setDbDriver(driverEle.getStringValue());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbcConfig.setDbUrl(urlEle.getStringValue());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbcConfig.setDbUser(userEle.getStringValue());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jdbcConfig.setDbPass(passwordEle.getStringValue());&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">synchronized</span>&nbsp;XmlConfigReader&nbsp;getInstance(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">if</span>(instance==<span style="color: #0000FF; ">null</span>){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;instance&nbsp;=&nbsp;<span style="color: #0000FF; ">new</span>&nbsp;XmlConfigReader();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;instance;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;JdbcConfig&nbsp;getJdbcConfig(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;<span style="color: #0000FF; ">this</span>.jdbcConfig;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><br /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><strong><span style="color: #ff0000; ">3、根据解析出了的配置信息完成数据库的连接</span></strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">下面是一个完成数据库连接操作的测试工具类<strong>DbUtil.java</strong></p><br /><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF; ">package</span>&nbsp;org.ml.drp.util;<br /><br /><span style="color: #0000FF; ">import</span>&nbsp;java.sql.Connection;<br /><span style="color: #0000FF; ">import</span>&nbsp;java.sql.DriverManager;<br /><span style="color: #0000FF; ">import</span>&nbsp;java.sql.SQLException;<br /><br /><span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;*&nbsp;封装数据库常用操作类<br />&nbsp;*&nbsp;</span><span style="color: #808080; ">@author</span><span style="color: #008000; ">&nbsp;MuLing<br />&nbsp;*<br />&nbsp;</span><span style="color: #008000; ">*/</span><br /><span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">class</span>&nbsp;DbUtil&nbsp;{<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">/**</span><span style="color: #008000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;取得数据库的连接<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;</span><span style="color: #808080; ">@return</span><span style="color: #008000; "><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000; ">*/</span><br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;Connection&nbsp;getConnection(){<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection&nbsp;conn&nbsp;=&nbsp;<span style="color: #0000FF; ">null</span>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">取得数据库连接字符串</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;JdbcConfig&nbsp;jdbcConfig&nbsp;=&nbsp;XmlConfigReader.getInstance().getJdbcConfig();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;DBDRIVER&nbsp;=&nbsp;jdbcConfig.getDbDriver();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;DBURL&nbsp;=&nbsp;jdbcConfig.getDbUrl();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;DBUSER&nbsp;=&nbsp;jdbcConfig.getDbUser();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;DBPASS&nbsp;=&nbsp;jdbcConfig.getDbPass();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">1:注册驱动</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">try</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class.forName(DBDRIVER);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(ClassNotFoundException&nbsp;e)&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">2：获取连接</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">try</span>&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn&nbsp;=&nbsp;DriverManager.getConnection(DBURL,&nbsp;DBUSER,&nbsp;DBPASS);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style="color: #0000FF; ">catch</span>&nbsp;(SQLException&nbsp;e)&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;e.printStackTrace();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">3:返回数据库连接</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">return</span>&nbsp;conn;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #008000; ">//</span><span style="color: #008000; ">测试数据库的连接是否成功</span><span style="color: #008000; "><br /></span>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000FF; ">public</span>&nbsp;<span style="color: #0000FF; ">static</span>&nbsp;<span style="color: #0000FF; ">void</span>&nbsp;main(String&nbsp;args[]){&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(DbUtil.getConnection());<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}</div><br />上完成了单例模式下使用dom4j来读取数据库配置文件，并实现数据库的连接操作。&nbsp;<br /><br /><br /><br /><br /></p><img src ="http://www.blogjava.net/hongqiang/aggbug/385091.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-08 23:37 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/08/385091.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>破除“系统学习”的情结</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/08/385090.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 08 Aug 2012 15:33:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/08/385090.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/385090.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/08/385090.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/385090.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/385090.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">常有同学想在自己课外学习的安排中，&#8220;系统地&#8221;学习点什么。这样的事情常发生在喜欢做A专业的事，却上了B专业，且A不等于B，甚至相似度(A, B)趋于无穷。对有些同学，一不留神发现自己的学习落后了不少，比如学计算机的，到大三了，却发现连简单程序也编不出来，再如学完高数了，才知道高数原来如此重要，于是想要系统地重学一遍。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　何为系统学习？系统学习就是要按照已有的一套规定，先学什么，再学什么，按步就班地走完一个流程。为什么要系统学习？将做事能专业些。规定从何而来？业界专家。系统学习有什么好处？基础扎实。系统学习的路线？先理论，再理论指导实践。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　这就怪了。当今大学饱受批评之一在于重理论，轻实践。而到了课外自己的安排，还也要走入这条巷子。深层的原因在于，我们要想学点东西，无意识地延续了一种并不是很合理的思维，学习的模式被单一化了。一边在批评着本专业系统化教学中的弊端，一方面在本来不受约束的自由安排中又要去追求这种系统化，谬矣。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　系统地学，意味着将开始一个比较庞大和长期的计划。雄心勃勃地起步，灰溜溜的，或者不知不觉地停止。这种情况我经历了不止一次。还有一种情况是，祥林嫂式地叨叨一生：&#8220;一直想系统学习一下&#8230;&#8230;，却没有机会。&#8221;</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　要想满足自己的兴趣，其实很简单，用合适的方式行动起来即可。喜欢电子的，先买个套件，备把烙铁，焊个收音机出来；喜欢计算机的，就先自学编个程序出来；喜欢经济的，读些经济学著作&#8230;&#8230;。系统学习的条件往往有些苛刻，所以不要寄望于系统学习。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　实际上，系统学习这个东东，确实用不着为之如此着迷。系统学习本身并没有什么太多的道理，那是对某方面知识的套装，是为了适应大规模人才培养而用的。一旦形成系统，也就意味着僵化，意味着单一标准，在这一套东西广为传播的同时，也为相应的学科进一步发展套上了枷锁，这是一个躲不开的悖论。单按这个系统培养出来的人才，没有特色，缺乏创新，这是现在教育的一个非常大的弊端。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　我们不能直接全盘否认系统学习，这种方法是有效的，也将继续持续。需要我们每个人做的，是不单一地依赖系统化，要突破这个所谓的系统，找出适合自己的办法，进而为这个系统做出贡献。这就是创新。要创新，就一定要有人突破系统的制约。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　一个最简单的问题，各行业都有个祖师爷，哪个祖师爷是科班出身，系统学习过的？在现实中，我们发现很多有所成就的人物往往是多面手，不能说他的每一面都是系统学来的。在职场中，复合型人才受欢迎，复合型人才不可以单一理解为上过几个专业，拿过几个学位。野路子出身，被智叟们看不上的，常常能做出大的成绩。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　在我理想的大学中，同学们的学习将是这样的：他们接受着一项专业教育，一方面由教授系统地传授着专业知识，接受着一种&#8220;正规&#8221;的训练，另一方面，学生能够根据自己的兴趣、感觉自由地拓展，拓展的内容有的是和系统相关的，有的完全是&#8220;节外生枝&#8221;。这是课内与课外有效的结合。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　破除&#8220;系统学习&#8221;的情结，根据自己当前的环境、条件，首先行动起来。在起步时，着重直接的体验，而专门的理论。在整个过程中，看重自己的感受，而不是专家的观点。坚持下来，你将有能力自由出入这个系统，面对的是更为广阔的空间。没有经过系统学习，实在不能不说是一件值得庆幸的事。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　有条件系统学习，或许可以乐一乐；而没有条件系统学习的，一定不要纠结。</span><br style="font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">　　有条件进入了系统学习轨道的，也要常想着&#8220;捣乱&#8221;，往系统外冲一冲。没有条件以系统学习开始的，不妨在野路子起步，甚至成为高手后，往系统这边看一看，这会让你上到一个新的境界。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><br /></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">总结一下：能进入系统学习轨道的人是幸运的，但也要提防着&#8220;系统&#8221;给你造成的限制；既然没有条件系统学习的，就不要去干等，先动起来再说。</p><img src ="http://www.blogjava.net/hongqiang/aggbug/385090.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-08 23:33 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/08/385090.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>探讨i++和++i</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/01/384557.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 01 Aug 2012 13:56:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/01/384557.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/384557.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/01/384557.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/384557.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/384557.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">文章的楼主连左值都可以运算，还若无其事得当作可以编译，在那讲解，若无其事就算了，可以当做没有发现编译问题，但是那讲解也太误导人了吧？然后我跟帖的楼下还出现一个&#8220;石破天&#8221;，以教导式的口吻，在那讲解，不知道的人岂不是就信了吗？真真一群害人之马，当然我只是指其中几位，很多跟帖的朋友，我自认还是不如的。</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">就为了这个影响广泛的害人帖子（在csdn上弹框出来，影响能不小吗？），我也来探讨一下i++，我是菜鸟，我不会用教导式口吻来讲解。</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">首先说文章楼主提到的</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">if((i++=j++)!=4){<img src="http://www.blogjava.net/Images/dot.gif"  alt="" />} &nbsp;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">看到这句代码我真想喷，因为这让我对自己产生了不自信，还去编译了一下，果然是错误的，左边怎么能够进行运算呢？楼主真强大...为什么昨天没有写文章，没有情绪激动，因</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">为我知道C++风格也是这样赋值，不知道能不能编译过去，但是今天看到跟帖的朋友说，VC98过不去，DEV-C++也过不去，我才感到真有一种被耍的感觉。&#8220;左值能运算吗？What&nbsp; the hell！"这一句，只是骂我自己怀疑自己，没有对其他任何人。</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">假设，楼主是手误，咱们来一个正确的能编译的代码讨论一下：</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">int&nbsp;i=4,j=3;&nbsp;&nbsp;&nbsp;<br />if((i&nbsp;=&nbsp;j++)&nbsp;!=&nbsp;4)&nbsp;{<img src="http://www.blogjava.net/Images/dot.gif"  alt="" />} &nbsp;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">j++的具体动作应该是怎样的，我想看过《Thinking in Java》的朋友都掌握得还不错，如果实在想找更深入一点探讨i++的书，个人看过《Java程序员面试宝典》，里面有提到i++这个部分，讲得很仔细。j++，是一个依赖于java里面的&#8220;中间缓存变量机制&#8221;来实现的，很多人都会念++在前就是&#8220;先加后赋&#8221;，++在后就是&#8220;先赋后加&#8221;，但是这个&#8220;赋&#8221;和这个&#8220;加&#8221;是针对哪个对象呢，有几个人能清楚的解释？&#8220;宝典&#8221;这本书上面的解释，个人觉得非常好，就来这里秀一段。首先，像文章中2楼所说那样：++的时间是以整个语句为衡量的，所以，什么时候自增，跟一整句运算语句有关，现在的情况是<span style="color: #ff0000; ">&nbsp;i = j++</span><span style="color: #000000; ">：这样一句应该被拆分为：</span></p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">temp&nbsp;=&nbsp;j;//先赋<br />j&nbsp;=&nbsp;j&nbsp;+&nbsp;1;//后加<br />i&nbsp;=&nbsp;temp;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">再来一个<span style="color: #ff0000; ">i = ++j</span><span style="color: #000000; ">：这一句应该被拆分为：</span></p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">j&nbsp;=&nbsp;j&nbsp;+&nbsp;1;//先加<br />temp&nbsp;=&nbsp;j;//后赋<br />i&nbsp;=&nbsp;temp;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">用这样的语句，来解释&#8220;赋&#8221;跟&#8220;加&#8221;应该是很明了的吧？记住，&#8220;加&#8221;只涉及了本身，&#8220;赋&#8221;涉及本身和中间缓存变量。</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">如何理解&#8220;++的时间是以整个语句为衡量的&#8221;？咱们来一段复杂的就可以很好地理解了，就拿那个被我喷的&#8220;石破天&#8221;的吧。</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">/*&nbsp;这个是原式，尊重版权，但是误导人*/<br />int&nbsp;i=10;<br />i=i++&nbsp;+&nbsp;i++;//20&nbsp;&nbsp;--这里应该会是21,note&nbsp;by&nbsp;jacob<br />i=++i&nbsp;+&nbsp;++i;//44&nbsp;&nbsp;--这里应该会是45,note&nbsp;by&nbsp;jacob<br />&nbsp;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">首先咱们把这都拆开来理解：</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">/*&nbsp;细说第一个&nbsp;i&nbsp;=&nbsp;i++&nbsp;+&nbsp;i&nbsp;++;&nbsp;*/<br />temp1&nbsp;=&nbsp;i;//temp1&nbsp;==&nbsp;10<br />i&nbsp;=&nbsp;i&nbsp;+&nbsp;1;//i&nbsp;==&nbsp;11;<br />temp2&nbsp;=&nbsp;i;//temp2&nbsp;==&nbsp;11<br />i&nbsp;=&nbsp;i&nbsp;+&nbsp;1;//i&nbsp;==&nbsp;12;<br />i&nbsp;=&nbsp;temp1&nbsp;+&nbsp;temp2;//i&nbsp;==&nbsp;21</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">/*第二个&nbsp;i&nbsp;=&nbsp;++i&nbsp;+&nbsp;++i;*/<br />i&nbsp;=&nbsp;i&nbsp;+&nbsp;1;<br />temp1&nbsp;=&nbsp;i;<br />i&nbsp;=&nbsp;i&nbsp;+&nbsp;1;<br />temp2&nbsp;=&nbsp;i;<br />i&nbsp;=&nbsp;temp1&nbsp;+temp2;</span></div></div><p style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><br />这样的例子，应该算是比较复杂的吧？如果需要，还可以来一个更加复杂的，不过不再详细解释，大家可以拿来推敲一下：</p><div bg_java"="" style="width: 685px; color: #333333; line-height: 25px; text-align: left; "><div style="background-color:#eeeeee;font-size:13px;border:1px solid #CCCCCC;padding-right: 5px;padding-bottom: 4px;padding-left: 4px;padding-top: 4px;width: 98%;word-break:break-all"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000; ">int&nbsp;j&nbsp;=0,k&nbsp;=&nbsp;0,h=0;<br />k&nbsp;=&nbsp;k++&nbsp;+&nbsp;k++&nbsp;+&nbsp;k++&nbsp;+&nbsp;++k;//k&nbsp;==&nbsp;7<br />j&nbsp;=&nbsp;++j&nbsp;+&nbsp;j++&nbsp;+&nbsp;j++&nbsp;+&nbsp;j++;//j&nbsp;==7;<br />h&nbsp;=&nbsp;++h&nbsp;+&nbsp;++h;</span></div></div><img src ="http://www.blogjava.net/hongqiang/aggbug/384557.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-01 21:56 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/01/384557.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript的延迟等待实现</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/01/384555.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 01 Aug 2012 13:50:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/01/384555.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/384555.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/01/384555.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/384555.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/384555.html</trackback:ping><description><![CDATA[<span style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;这段时间遇到一个问题：使用ajax生成一个列表，然后使用sorttable.js对这个列表进行排序。问题在于：生成的列表还没出现，排序已经开始了，结果没有找到列表报错。解决方法：</span>&nbsp;<br /><div style="font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; padding-right: 5px; padding-bottom: 4px; padding-left: 4px; padding-top: 4px; width: 98%; word-break: break-all; background-color: #eeeeee; "><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->&nbsp;function&nbsp;ifExist(table){<br />&nbsp;&nbsp;&nbsp;&nbsp;if(table.tBodies[0]==null)<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;setTimeout(&nbsp;function(){ifExist(table);},&nbsp;1000);&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;else<br />&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;sorttable.makeSortable(table);<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp;}</div><br /><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">判断节点是否生成了，如果没有，那么就等待1秒，再循环执行。一切ok了！</p><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">最后，补充一下关于javascript同步和异步的问题（转载）：</p><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>一、同步加载与异步加载的形式</strong></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>1. 同步加载</strong></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">我们平时最常使用的就是这种同步加载形式：</div><pre style="white-space: pre-wrap; word-wrap: break-word; line-height: 25px; text-align: left; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; "><span style="color: #808030; ">&lt;</span>script src<span style="color: #808030; ">=</span>"http://yourdomain.com/script.js"<span style="color: #808030; ">&gt;</span><span style="color: #808030; ">&lt;</span><span style="color: #808030; ">/</span>script<span style="color: #808030; ">&gt;</span> </pre><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><div>同步模式，又称阻塞模式，会阻止浏览器的后续处理，停止了后续的解析，因此停止了后续的文件加载（如图像）、渲染、代码执行。</div><div>js 之所以要同步执行，是因为 js 中可能有输出 document 内容、修改dom、重定向等行为，所以默认同步执行才是安全的。</div><div>以前的一般建议是把&lt;script&gt;放在页面末尾&lt;/body&gt;之前，这样尽可能减少这种阻塞行为，而先让页面展示出来。</div></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">简单说：加载的网络 timeline 是瀑布模型，而异步加载的 timeline 是并发模型。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>2. 常见异步加载（Script DOM Element）</strong></p><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="color: #808030; ">(</span><span style="font-weight: bold; ">function</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span> {      <span style="font-weight: bold; ">var</span> s <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span>;      s<span style="color: #808030; ">.</span>type <span style="color: #808030; ">=</span> 'text/javascript';      s<span style="color: #808030; ">.</span>async <span style="color: #808030; ">=</span> true;      s<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> 'http://yourdomain.com/script.js';      <span style="font-weight: bold; ">var</span> x <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>getElementsByTagName<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span><span style="color: #808030; ">[</span>0<span style="color: #808030; ">]</span>;      x<span style="color: #808030; ">.</span>parentNode<span style="color: #808030; ">.</span>insertBefore<span style="color: #808030; ">(</span>s<span style="color: #808030; ">,</span> x<span style="color: #808030; ">)</span>;  }<span style="color: #808030; ">)</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;</pre><br />异步加载又叫非阻塞，浏览器在下载执行 js 同时，还会继续进行后续页面的处理。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">这种方法是在页面中&lt;script&gt;标签内，用 js 创建一个 script 元素并插入到 document 中。这样就做到了非阻塞的下载 js 代码。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">async属性是HTML5中新增的异步支持，见后文解释，加上好（不加也不影响）。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">此方法被称为 Script DOM Element 法，不要求 js 同源。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">将js代码包裹在匿名函数中并立即执行的方式是为了保护变量名泄露到外部可见，这是很常见的方式，尤其是在 js 库中被普遍使用。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><div></div><div>例如 Google Analytics 和 Google+ Badge 都使用了这种异步加载代码：</div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="color: #808030; ">(</span><span style="font-weight: bold; ">function</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span> {      <span style="font-weight: bold; ">var</span> ga <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span>; ga<span style="color: #808030; ">.</span>type <span style="color: #808030; ">=</span> 'text/javascript'; ga<span style="color: #808030; ">.</span>async <span style="color: #808030; ">=</span> true;      ga<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> <span style="color: #808030; ">(</span>'https:' <span style="color: #808030; ">==</span> document<span style="color: #808030; ">.</span>location<span style="color: #808030; ">.</span>protocol ? 'https://ssl' : 'http://www'<span style="color: #808030; ">)</span> <span style="color: #808030; ">+</span> '.google-analytics.com/ga.js';      <span style="font-weight: bold; ">var</span> s <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>getElementsByTagName<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span><span style="color: #808030; ">[</span>0<span style="color: #808030; ">]</span>; s<span style="color: #808030; ">.</span>parentNode<span style="color: #808030; ">.</span>insertBefore<span style="color: #808030; ">(</span>ga<span style="color: #808030; ">,</span> s<span style="color: #808030; ">)</span>;  }<span style="color: #808030; ">)</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;  </pre></div><div><span style="font-family: monospace; color: #808030; white-space: pre; ">(</span><span style="font-family: monospace; font-weight: bold; white-space: pre; ">function</span><span style="font-family: monospace; color: #808030; white-space: pre; ">(</span><span style="font-family: monospace; color: #808030; white-space: pre; ">)</span></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; ">    {<span style="font-weight: bold; ">var</span> po <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement<span style="color: #808030; ">(</span>"script"<span style="color: #808030; ">)</span>;     po<span style="color: #808030; ">.</span>type <span style="color: #808030; ">=</span> "text/javascript"; po<span style="color: #808030; ">.</span>async <span style="color: #808030; ">=</span> true;po<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> "https://apis.google.com/js/plusone.js";     <span style="font-weight: bold; ">var</span> s <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>getElementsByTagName<span style="color: #808030; ">(</span>"script"<span style="color: #808030; ">)</span><span style="color: #808030; ">[</span>0<span style="color: #808030; ">]</span>;     s<span style="color: #808030; ">.</span>parentNode<span style="color: #808030; ">.</span>insertBefore<span style="color: #808030; ">(</span>po<span style="color: #808030; ">,</span> s<span style="color: #808030; ">)</span>;  }<span style="color: #808030; ">)</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;  </pre></div><div>但是，<strong>这种加载方式在加载执行完之前会阻止 onload 事件的触发</strong>，而现在很多页面的代码都在 onload 时还要执行额外的渲染工作等，所以还是会阻塞部分页面的初始化处理。</div><div style="font-weight: bold; "><strong><br /></strong></div>3. onload 时的异步加载</div><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></p><pre style="white-space: pre-wrap; word-wrap: break-word; line-height: 25px; text-align: left; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #ffffff; "><span style="color: #808030; ">(</span><span style="font-weight: bold; ">function</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span> {      <span style="font-weight: bold; ">function</span> async_load<span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>{          <span style="font-weight: bold; ">var</span> s <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span>;          s<span style="color: #808030; ">.</span>type <span style="color: #808030; ">=</span> 'text/javascript';          s<span style="color: #808030; ">.</span>async <span style="color: #808030; ">=</span> true;          s<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> 'http://yourdomain.com/script.js';          <span style="font-weight: bold; ">var</span> x <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>getElementsByTagName<span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span><span style="color: #808030; ">[</span>0<span style="color: #808030; ">]</span>;          x<span style="color: #808030; ">.</span>parentNode<span style="color: #808030; ">.</span>insertBefore<span style="color: #808030; ">(</span>s<span style="color: #808030; ">,</span> x<span style="color: #808030; ">)</span>;      }      <span style="font-weight: bold; ">if</span> <span style="color: #808030; ">(</span>window<span style="color: #808030; ">.</span>attachEvent<span style="color: #808030; ">)</span>          window<span style="color: #808030; ">.</span>attachEvent<span style="color: #808030; ">(</span>'onload'<span style="color: #808030; ">,</span> async_load<span style="color: #808030; ">)</span>;      <span style="font-weight: bold; ">else</span>          window<span style="color: #808030; ">.</span>addEventListener<span style="color: #808030; ">(</span>'load'<span style="color: #808030; ">,</span> async_load<span style="color: #808030; ">,</span> false<span style="color: #808030; ">)</span>;  }<span style="color: #808030; ">)</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;  </pre><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">这和前面的方式差不多，但关键是它不是立即开始异步加载 js ，而是在 onload 时才开始异步加载。这样就解决了阻塞 onload 事件触发的问题。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">补充：<strong>DOMContentLoaded 与 OnLoad 事件</strong></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">DOMContentLoaded : 页面(document)已经解析完成，页面中的dom元素已经可用。但是页面中引用的图片、subframe可能还没有加载完。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">OnLoad：页面的所有资源都加载完毕（包括图片）。浏览器的载入进度在这时才停止。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">这两个时间点将页面加载的timeline分成了三个阶段。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><p style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>4.异步加载的其它方法</strong></p><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">由于Javascript的<strong>动态特性</strong>，还有很多异步加载方法：</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><ul><li>XHR Eval</li><li>XHR Injection</li><li>Script in Iframe</li><li>Script Defer</li><li>document.write Script Tag</li><li>还有一种方法是用 setTimeout 延迟0秒 与 其它方法组合。</li></ul></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>XHR Eval&nbsp;</strong>：通过 ajax 获取js的内容，然后 eval 执行。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="font-weight: bold; ">var</span> xhrObj <span style="color: #808030; ">=</span> getXHRObject<span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;   xhrObj<span style="color: #808030; ">.</span>onreadystatechange <span style="color: #808030; ">=</span>      <span style="font-weight: bold; ">function</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span> {        <span style="font-weight: bold; ">if</span> <span style="color: #808030; ">(</span> xhrObj<span style="color: #808030; ">.</span>readyState <span style="color: #808030; ">!=</span> 4 <span style="color: #808030; ">)</span> <span style="font-weight: bold; ">return</span>;       <span style="font-weight: bold; ">eval</span><span style="color: #808030; ">(</span>xhrObj<span style="color: #808030; ">.</span>responseText<span style="color: #808030; ">)</span>;     };   xhrObj<span style="color: #808030; ">.</span>open<span style="color: #808030; ">(</span>'GET'<span style="color: #808030; ">,</span> 'A.js'<span style="color: #808030; ">,</span> true<span style="color: #808030; ">)</span>;   xhrObj<span style="color: #808030; ">.</span>send<span style="color: #808030; ">(</span>''<span style="color: #808030; ">)</span>;  </pre></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>Script in Ifram</strong>e：创建并插入一个iframe元素，让其异步执行 js 。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="font-weight: bold; ">var</span> iframe <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement<span style="color: #808030; ">(</span>'iframe'<span style="color: #808030; ">)</span>;   document<span style="color: #808030; ">.</span>body<span style="color: #808030; ">.</span>appendChild<span style="color: #808030; ">(</span>iframe<span style="color: #808030; ">)</span>;   <span style="font-weight: bold; ">var</span> doc <span style="color: #808030; ">=</span> iframe<span style="color: #808030; ">.</span>contentWindow<span style="color: #808030; ">.</span>document;   doc<span style="color: #808030; ">.</span>open<span style="color: #808030; ">(</span><span style="color: #808030; ">)</span><span style="color: #808030; ">.</span>write<span style="color: #808030; ">(</span>'&lt;body onload="insertJS()"&gt;'<span style="color: #808030; ">)</span>;   doc<span style="color: #808030; ">.</span>close<span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;  </pre></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><strong>GMail Mobile</strong>：页内 js 的内容被注释，所以不会执行，然后在需要的时候，获取script元素中 text 内容，去掉注释后 eval 执行。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="color: #808030; ">&lt;</span>script type<span style="color: #808030; ">=</span>"text/javascript"<span style="color: #808030; ">&gt;</span>   <span style="color: #696969; ">/* </span>  <span style="color: #696969; ">var ...  </span>  <span style="color: #696969; ">*/</span>   <span style="color: #808030; ">&lt;</span><span style="color: #808030; ">/</span>script<span style="color: #808030; ">&gt;</span>  </pre></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">详见参考资料中2010年的Velocity 大会 Steve Souders 和淘宝的那两个讲义。</div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "></div><div style="color: #362e2b; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; "><div></div><div><strong>二、async 和 defer 属性</strong></div><div><strong>1. defer 属性</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="color: #808030; ">&lt;</span>script src<span style="color: #808030; ">=</span>"file.js" defer<span style="color: #808030; ">&gt;</span><span style="color: #808030; ">&lt;</span><span style="color: #808030; ">/</span>script<span style="color: #808030; ">&gt;</span> </pre></div><div>defer属性声明这个脚本中将不会有 document.write 或 dom 修改。</div><div>浏览器将会并行下载 file.js 和其它有 defer 属性的script，而不会阻塞页面后续处理。</div><div></div><div>defer属性在IE 4.0中就实现了，超过13年了！Firefox 从 3.5 开始支持defer属性 。</div><div>注：所有的defer 脚本保证是<strong>按顺序依次执行</strong>的。</div><div></div><div></div><div><strong>2. async 属性</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="color: #808030; ">&lt;</span>script src<span style="color: #808030; ">=</span>"file.js" async<span style="color: #808030; ">&gt;</span><span style="color: #808030; ">&lt;</span><span style="color: #808030; ">/</span>script<span style="color: #808030; ">&gt;</span> </pre></div><div>async属性是HTML5新增的。作用和defer类似，但是它将在下载后尽快执行，<strong>不能保证脚本会按顺序执行</strong>。它们将在onload 事件之前完成。</div><div>Firefox 3.6、Opera 10.5、IE 9 和 最新的Chrome 和 Safari 都支持 async 属性。可以同时使用 async 和 defer，这样IE 4之后的所有 IE 都支持异步加载。</div><div></div><div><strong>3. 详细解释</strong></div><div><div></div><div><strong>&lt;script&gt; 标签在 HTML 4.01 与 HTML5 的区别：</strong></div><div><ul><li>type 属性在HTML 4中是必须的，在HTML5中是可选的。</li><li>async 属性是HTML5中新增的。</li><li>个别属性（xml:space）在HTML5中不支持。</li></ul></div></div><div></div><div><strong>说明：</strong></div><div><ol><li>没有 async 属性，script 将立即获取（下载）并执行，然后才继续后面的处理，这期间阻塞了浏览器的后续处理。</li><li>如果有 async 属性，那么 script 将被异步下载并执行，同时浏览器继续后续的处理。</li><li>HTML4中就有了defer属性，它提示浏览器这个 script 不会产生任何文档元素（没有document.write），因此浏览器会继续后续处理和渲染。</li><li>如果没有 async 属性 但是有 defer 属性，那么script 将在页面parse之后执行。</li><li>如果同时设置了二者，那么 defer 属性主要是为了让不支持 async 属性的老浏览器按照原来的 defer 方式处理，而不是同步方式。</li></ol></div><div></div><div>另参见官方说明：<a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#attr-script-async" rel="nofollow" target="_blank" style="color: #6a3906; text-decoration: none; ">script async</a></div><div></div><div>个人补充：</div><div>既然 HTML5 中已经支持异步加载，为什么还要使用前面推荐的那种麻烦（动态创建 script 元素）的方式？</div><div>答：为了兼容尚不支持 async 老浏览器。如果将来所有浏览器都支持了，那么直接在script中加上async 属性是最简单的方式。</div><div></div><div></div><div><strong>三、延迟加载（lazy loading）</strong></div><div></div><div><div>前面解决了异步加载（async loading）问题，再谈谈什么是延迟加载。</div><div>延迟加载：有些 js 代码并不是页面初始化的时候就立刻需要的，而稍后的某些情况才需要的。延迟加载就是一开始并不加载这些暂时不用的js，而是在需要的时候或稍后再通过js 的控制来异步加载。</div></div><div></div><div>也就是将 js 切分成许多模块，页面初始化时只加载需要立即执行的 js ，然后其它 js 的加载延迟到第一次需要用到的时候再加载。</div><div>特别是页面有大量不同的模块组成，很多可能暂时不用或根本就没用到。</div><div>就像图片的延迟加载，在图片出现在可视区域内时（在滚动条下拉）才加载显示图片。</div><div></div><div></div><div><div><strong>四、script 的两阶段加载 与 延迟执行（lazy execution）</strong></div><div><div>JS的加载其实是由两阶段组成：下载内容（download bytes）和执行（parse and execute）。</div><div><strong>浏览器在下载完 js 的内容后就会立即对其解析和执行，不管是同步加载还是异步加载。</strong></div><div></div><div>前面说的异步加载，解决的只是下载阶段的问题，但代码在下载后会立即执行。</div><div>而浏览器在解析执行 JS 阶段是阻塞任何操作的，这时的浏览器处于无响应状态。</div><div></div><div><div>我 们都知道通过网络下载 script&nbsp; 需要明显的时间，但容易忽略了第二阶段，解析和执行也是需要时间的。script的解析和执行所花的时间比我们想象的要多，尤其是script&nbsp; 很多很大的时候。有些是需要立刻执行，而有些则不需要（比如只是在展示某个界面或执行某个操作时才需要）。</div><div>这些script 可以延迟执行，先异步下载缓存起来，但不立即执行，而是在第一次需要的时候执行一次。</div><div></div><div>利用特殊的技巧可以做到 下载 与 执行的分离 (再次感谢 javascript 的动态特性)。比如将 JS 的内容作为 Image或 object 对象加载缓存起来，所以就不会立即执行了，然后在第一次需要的时候再执行。</div><div></div><div>此部分的更多解释 请查看末尾参考资料中 ControlJS 的相关链接。</div></div></div><div></div><div><strong>小技巧：</strong></div><div>1.&nbsp;<strong>模拟较长的下载时间</strong>：</div><div>写个后端脚本，让其 sleep 一定时间。如在 jsp 中 Thread.sleep(5000); ，这样5秒后才能收到内容。</div><div></div><div>2.&nbsp;<strong>模拟较长的 js 代码执行时间</strong>（因为这步一般比较快不容易观察到）：</div><div><div>var t_start = Number(new Date());</div><div>while ( t_start + 5000 &gt; Number(new Date()) ) {}</div></div><div>这个代码将使 js 执行5秒才能完成！</div><div></div></div><div></div><div><strong>五、script 标签使用的历史</strong></div><div><strong><br /></strong></div><div><strong>1. script 放在 HEAD 中</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; ">&lt;<span style="font-weight: bold; ">head</span>&gt;   &lt;<span style="font-weight: bold; ">script src=&#8220;&#8230;&#8221;</span>&gt;&lt;/<span style="font-weight: bold; ">script</span>&gt;   &lt;/<span style="font-weight: bold; ">head</span>&gt;  </pre><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><ul><li><span style="font-family: Arial, Helvetica, sans-serif; white-space: normal; ">阻止了后续的下载；</span></li><li><span style="font-family: Arial, Helvetica, sans-serif; white-space: normal; ">在IE 6-7 中 script 是顺序下载的，而不是现在的 &#8220;并行下载、顺序执行&#8221; 的方式；</span></li><li><span style="font-family: Arial, Helvetica, sans-serif; white-space: normal; ">在下载<strong>和</strong>解析执行阶段阻止渲染（rendering）；</span></li></ul></pre></div><div></div><div><strong>2. script 放在页面底部（2007）</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; ">...   &lt;<span style="font-weight: bold; ">script src=&#8220;&#8230;&#8221;</span>&gt;&lt;/<span style="font-weight: bold; ">script</span>&gt;   &lt;/<span style="font-weight: bold; ">body</span>&gt;  </pre><ul><li>不阻止其它下载；</li><li>在IE 6-7 中 script 是顺序下载的；</li><li>在下载<strong>和</strong>解析执行阶段阻止渲染（rendering）；</li></ul></div><div></div><div></div><div><strong>3. 异步加载script（2009）</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="font-weight: bold; ">var</span> se <span style="color: #808030; ">=</span> document<span style="color: #808030; ">.</span>createElement  <span style="color: #808030; ">(</span>'script'<span style="color: #808030; ">)</span>;   se<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> 'http://anydomain.com/A.js';   document<span style="color: #808030; ">.</span>getElementsByTagName<span style="color: #808030; ">(</span>'head'<span style="color: #808030; ">)</span>   <span style="color: #808030; ">[</span>0<span style="color: #808030; ">]</span><span style="color: #808030; ">.</span>appendChild<span style="color: #808030; ">(</span>se<span style="color: #808030; ">)</span>;  </pre></div><div>这就是本文主要说的方式。</div><div><ul><li>不阻止其它下载；</li><li>在所有浏览器中，script都是并行下载；</li><li><strong>只在</strong>解析执行阶段阻止渲染（rendering）；</li></ul></div><div></div><div><strong>4. 异步下载 + 按需执行 (2010)</strong></div><div><pre style="white-space: pre-wrap; word-wrap: break-word; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; color: #000000; "><span style="font-weight: bold; ">var</span> se <span style="color: #808030; ">=</span> <span style="font-weight: bold; ">new</span> <span style="color: #797997; ">Image</span><span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;   se<span style="color: #808030; ">.</span>onload <span style="color: #808030; ">=</span> registerScript<span style="color: #808030; ">(</span><span style="color: #808030; ">)</span>;   se<span style="color: #808030; ">.</span>src <span style="color: #808030; ">=</span> 'http://anydomain.com/A.js';  <span style="line-height: 20px; ">把下载 js 与 解析执行 js 分离出来</span></pre></div><div><ul><li>不阻止其它下载；</li><li>在所有浏览器中，script都是并行下载；</li><li><strong>不阻止</strong>渲染（rendering）直到真正需要时；</li></ul></div><div></div><div></div><div><strong>六、异步加载的问题</strong></div><div>在异步加载的时候，无法使用 document.write 输出文档内容。</div><div>在同步模式下，document.write 是在<strong>当前 script 所在的位置</strong>输 出文档的。而在异步模式下，浏览器继续处理后续页面内容，根本无法确定 document.write&nbsp; 应该输出到什么位置，所以异步模式下 document.write 不可行。而到了页面已经 onload&nbsp; 之后，再执行 document.write 将导致当前页面的内容被清空，因为它会自动触发 document.open 方法。</div><div></div><div>实际上document.write的名声并不好，最好少用。</div><div></div><div><div>替代方法：</div><div>1. 虽然异步加载不能用 document.write，但还是可以onload之后执行操作dom（创建dom或修改dom）的，这样可以实现一些自己的动态输出。比如要在页面异步创建一个浮动元素，<strong>这和它在页面中的位置就没关系了</strong>，只要创建出该dom元素添加到 document 中即可。</div></div><div>2. 如果需要在<strong>固定位置</strong>异步生成元素的内容，那么可以在该固定位置设置一个dom元素作为目标，这样就知道位置了，异步加载之后就可以对这个元素进行修改。</div><div></div><div></div><div></div><div><strong>六、JS 模块化管理</strong></div><div>异步加载，需要将所有 js 内容按模块化的方式来切分组织，其中就存在依赖关系，而异步加载不保证执行顺序。</div><div>另外，namespace 如何管理 等相关问题。这部分已超出本文内容，可参考：</div><div><a href="http://requirejs.org/" rel="nofollow" target="_blank" style="color: #6a3906; text-decoration: none; ">RequireJS</a>&nbsp;、&nbsp;<a href="http://www.commonjs.org/" rel="nofollow" target="_blank" style="color: #6a3906; text-decoration: none; ">CommonJS</a>&nbsp;以及 王保平(淘宝)的&nbsp;<a href="http://seajs.com/" rel="nofollow" target="_blank" style="color: #6a3906; text-decoration: none; ">SeaJS</a>&nbsp;及其<a href="http://lifesinger.wordpress.com/" rel="nofollow" target="_blank" style="color: #6a3906; text-decoration: none; ">博客</a>&nbsp;。</div><div></div><div><strong>七、JS最佳实践：</strong></div><div>1. 最小化 js 文件，利用压缩工具将其最小化，同时开启http gzip压缩。工具：</div><div>2. 尽量不要放在 &lt;head&gt; 中，尽量放在页面底部，最好是&lt;/body&gt;之前的位置</div><div>3. 避免使用 document.write 方法</div><div>4. 异步加载 js ，使用非阻塞方式，就是此文内容。</div><div>5. 尽量不直接在页面元素上使用 Inline Javascript，如onClick 。有利于统一维护和缓存处理。</div></div><br /><img src ="http://www.blogjava.net/hongqiang/aggbug/384555.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-01 21:50 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/01/384555.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用谷歌jquery库文件的理由</title><link>http://www.blogjava.net/hongqiang/archive/2012/08/01/384553.html</link><dc:creator>张慧</dc:creator><author>张慧</author><pubDate>Wed, 01 Aug 2012 13:43:00 GMT</pubDate><guid>http://www.blogjava.net/hongqiang/archive/2012/08/01/384553.html</guid><wfw:comment>http://www.blogjava.net/hongqiang/comments/384553.html</wfw:comment><comments>http://www.blogjava.net/hongqiang/archive/2012/08/01/384553.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/hongqiang/comments/commentRss/384553.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hongqiang/services/trackbacks/384553.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">使用谷歌jquery库文件的理由</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">最</span><a href="http://www.jqueryba.com/" target="_blank" style="color: #336699; text-decoration: none; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">近前端开发</a><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">看到，那些引用jquery的文件那些网站，好多是使用谷歌的库；像这样的&lt;script type=&#8221;text/javascript&#8221;src=&#8221;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#8220;&gt;&lt;/script&gt;(最近发展到1.7.1版本的，好神速呐，前两天还看到一哥们用的1.2.6感慨啊。。。。)</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">像上面这样加载jquery通过谷歌的CDN-Content Delivery Network（内容分发网络）来让你的网站加载jquery库文件。有的同学可能会问了，为什么要加载谷歌的jquery库文件呢？（PS：我们一般不 都是加载自己服务器上的jquery库文件的吗？）。呵呵~~之前也和大家一样想的，也一直都是加载自己的服务器上的jquery文件。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">下面我来和大家说说，使用谷歌加载jquery库文件的好处。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">1，增加网页的同时载入速度</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">为了避免服务的过载，浏览器限制了同时连接的数目，依据不同的浏览器，这个限制可能是每个机房仅仅两个之少。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">使用谷歌的AJAX内容服务网络来响应你的网站，使你本地服务器上更多服务可以同时进行。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">2，减少等待时间</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">大家应该也差不多，在感慨jquery的强大，也在感慨jquery的团队也是如此之强大，呵呵~现在最新的jquery已经出到1.7.1版本了呢，但是让人很不爽的是即使是mini压缩过后的代码都有83.2KB。但是不知道大家有没有去官方首页看过。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">CDN-Content Delivery Network（内容分发网络）的缩写，通过各种各样的服务途径把你的一些静态内容分散开来，当用户的浏览器提交这些文件的链接请求，他们便会自动下载网络上最近的可用的文件。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">因为这个原因：任何使用你的服务的用户从谷歌下载JQuery库都将获得比从你自己的服务器上下载更快的速度。其实有很多的CDN服务可与谷歌的相比拟，但是他们很难超越谷歌的免费服务的优势，这个益处足以决定问题，但这仅仅是一部分。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">3，更好的缓存</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">利用谷歌AJAX图书馆内容发布服务的最大好处是你的用户根本不需要下载jQuery. 不论你的缓存多么强大，如果你用自己的服务器提供jQuery，那么你的用户至少要下载一次它，某个用户很有可能在他们浏览器的缓存区里下载了许多完全相 同的jQuery.min.js的拷贝版本，但是当他们第一次访问你的网站的时候，这些拷贝版本会被忽略。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">另一方面，当浏览器检测到同样版本的指向谷歌的链接，它就会知道这是下载同一个文件，不仅是谷歌的服务器会返回一个304（不需要修改文件的指令，即服务器上的文件未改动过）来回复一个重复的请求，而且会命令浏览器的缓存该文件长达一年的时间。http://www.jqueryba.com/14.html</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">这意味着即使一些人访问了数百的使用谷歌服务的jQuery网站,他们只需要下载一次就够了。</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">不过好像最近天朝对谷歌的东西有点反感呀，就像以前谷歌生气出走香港一样，有的时候谷歌的东西会打不开，那么会不会有一天使用这种方式加载jquery库文件也会失败呢？呵呵~~万事皆有可能，呵呵~不要紧，此处有一个万全的方法：</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;&lt;script type=text/javascript src=&#8221;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&#8221;&gt;&lt;/script&gt;</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">&lt;script&gt;!window.jQuery &amp;&amp; document.write(&#8216;&lt;script src=&#8221;jquery-1.7.1.min.js&#8221;&gt;&lt;\/script &gt;&#8217;);&lt;/script&gt;</span><br style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; " /><span style="color: #333333; font-family: Arial; line-height: 25px; text-align: left; background-color: #ffffff; ">将上面的代码放到你的html代码的头部。意义是这样的：首先去加载谷歌的jquery库文件，如果没有加载成功的话，那么就只好加载自己服务器上的jquery库文件咯。</span><img src ="http://www.blogjava.net/hongqiang/aggbug/384553.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hongqiang/" target="_blank">张慧</a> 2012-08-01 21:43 <a href="http://www.blogjava.net/hongqiang/archive/2012/08/01/384553.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>