﻿<?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-JAVA涂鸦-文章分类-J2SE</title><link>http://www.blogjava.net/rickhunter/category/3461.html</link><description>关于JAVA的点点滴滴</description><language>zh-cn</language><lastBuildDate>Fri, 02 Nov 2007 09:01:51 GMT</lastBuildDate><pubDate>Fri, 02 Nov 2007 09:01:51 GMT</pubDate><ttl>60</ttl><item><title>jdom操作xml</title><link>http://www.blogjava.net/rickhunter/articles/64739.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Mon, 21 Aug 2006 03:18:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/64739.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/64739.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/64739.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/64739.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/64739.html</trackback:ping><description><![CDATA[JDOM是Breet Mclaughlin和Jason Hunter两大Java高手的创作成果，2000年初，JDOM作为一个开放源代码项目正式开始研发。JDOM是一种解析XML的Java工具包。<br /><br />
  JDOM的二进制版本下载：<a href="http://www.jdom.org/downloads/index.html">http://www.jdom.org/downloads/index.html</a><br /><br />
  把解压后的jdom.jar文件加到项目的类路径中，另外便于调试，还要下载它的源代码。<br /><br />一、解析XML<br />要解析的XML文件：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;?</span><span style="color: rgb(0, 0, 0);">xml version</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> encoding</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">gb2312</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">books</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />   </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">book email</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">zhoujunhui</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">rjzjh</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />     </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">price</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">60.0</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">price</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">book</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">books</span><span style="color: rgb(0, 0, 0);">&gt;</span></div><br /><br />解析XML的java文件：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.IOException;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.input.SAXBuilder; <br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Test {<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> args<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">        SAXBuilder sb</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> SAXBuilder(</span>false<span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">        Document doc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">            doc </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> sb.build(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">sample.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (JDOMException e) {<br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">            e.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">            e.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">        } <br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">        Element root</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">doc.getRootElement(); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取根元素</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        List list</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">root.getChildren(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">book</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">取名字为book的所有元素</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">list.size();i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">            Element element</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">(Element)list.get(i);<br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">            String email</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">element.getAttributeValue(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">email</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 0, 0);">            String name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">element.getChildText(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">            String price</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">element.getChildText(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">price</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);">            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">name:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">name);<br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">price:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">price);<br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">            System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">email:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">email);<br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 0, 0);"></span></div><br />二、生成XML：<br />java文件：<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com;<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.FileWriter;<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.io.IOException;<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.input.SAXBuilder; <br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.jdom.output.XMLOutputter;<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> Test {<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> args<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) {<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第一步，创建根元素 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">        Element carElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">car</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">        Document myDocument </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Document(carElement); <br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">因为一个 XML 文档必须一直有一个唯一的根元素，所以 Document 将 Element 放在它的构造器中。 <br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 128, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第二步，添加一个 Attribute </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">        carElement.setAttribute(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Attribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">vin</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">123fhg5869705iop90</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">27</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第三步，添加其它元素 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">28</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">29</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">make</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addContent(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Toyota</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">30</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">31</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">model</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addContent(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Celica</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">32</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">year</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addContent(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1997</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">33</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">color</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addContent(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">green</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">34</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Element(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">license</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).addContent(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1ABC234</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).setAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">state</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">CA</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">35</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">36</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第四步，添加一条注释 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">37</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">38</span> <span style="color: rgb(0, 0, 0);">        carElement.addContent(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Comment(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Description of a car</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)); <br /></span><span style="color: rgb(0, 128, 128);">39</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">40</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第五步，读一个子元素 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">41</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">42</span> <span style="color: rgb(0, 0, 0);">        Element yearElement </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> carElement.getChild(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">year</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br /></span><span style="color: rgb(0, 128, 128);">43</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">44</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第六步，删除子元素 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">45</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">46</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> removed </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> carElement.removeChild(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">year</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); <br /></span><span style="color: rgb(0, 128, 128);">47</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">48</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">第七步，存盘 </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">49</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        XMLOutputter outputter </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XMLOutputter();</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">用于输出jdom 文档</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">50</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        FileWriter writer;<br /></span><span style="color: rgb(0, 128, 128);">51</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">52</span> <span style="color: rgb(0, 0, 0);">            writer </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileWriter(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">myFile.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">53</span> <span style="color: rgb(0, 0, 0);">            outputter.output(myDocument, writer); <br /></span><span style="color: rgb(0, 128, 128);">54</span> <span style="color: rgb(0, 0, 0);">            writer.close();<br /></span><span style="color: rgb(0, 128, 128);">55</span> <span style="color: rgb(0, 0, 0);">        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br /></span><span style="color: rgb(0, 128, 128);">56</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> TODO 自动生成 catch 块</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">57</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">            e.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">58</span> <span style="color: rgb(0, 0, 0);">        } <br /></span><span style="color: rgb(0, 128, 128);">59</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);">60</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">61</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">62</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">63</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">64</span> <span style="color: rgb(0, 0, 0);"></span></div><br />生成的XML: <br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">&lt;?</span><span style="color: rgb(0, 0, 0);">xml version</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> encoding</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF-8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">?&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">car vin</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">123fhg5869705iop90</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">make</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Toyota</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">make</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">model</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Celica</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">model</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">color</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">green</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">color</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">license state</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">CA</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">1ABC234</span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">license</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;!--</span><span style="color: rgb(0, 0, 0);">Description of a car</span><span style="color: rgb(0, 0, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">car</span><span style="color: rgb(0, 0, 0);">&gt;</span></div><br /><img src ="http://www.blogjava.net/rickhunter/aggbug/64739.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2006-08-21 11:18 <a href="http://www.blogjava.net/rickhunter/articles/64739.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>学习J2EE所看的书籍</title><link>http://www.blogjava.net/rickhunter/articles/45346.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Wed, 10 May 2006 01:35:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/45346.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/45346.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/45346.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/45346.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/45346.html</trackback:ping><description><![CDATA[<div align="left"><span style="font-size: 15px"><font size="3">J2EE的学习应该循序渐进，一本好的书能够使你很快上手和深入。在学习J2EE之前，我们要把SQL学好，基本上，程序设计都会跟数据库打交道，如果SQL没学好，就如同房子没有基脚一样，学习SQL需要大量的练习才能真正的体会其中的精髓。<br />
在入门之初，只需要买本一二十元的SQL入门书籍看看，了解数据库和SQL的基础知识。在深入学习SQL时，SQLServer2000的帮助文档是再好不过的教材了，只是内容显得过于庞大。<br />
在这里，我推荐一本书，可以看作是SQLServer2000的帮助文档的浓缩版本，方便平常翻阅查询。<br />
</font><span style="font-size: 15px"><strong><font size="3">SQL编程实用大全（精华版）<br />
</font></strong></span><span style="font-size: 15px"><font size="3">相关联接：<br />
</font><a href="http://www.dearbook.com.cn/book/29898"><font color="#0000ff" size="3">http://www.dearbook.com.cn/book/29898</font> </a><br />
<br />
</span><font size="3">接下来是java语言的学习。<br />
</font><br />
<strong>Java语言程序设计</strong> </span></div>
<p>这是一本很好的Java入门教材，该说的都说了，尽管不是很深入，但对入门而言已经足够了。<br />
相关联接：<br />
<a class="" title="" href="http://www.huachu.com.cn/itbook/itbookinfo.asp?lbbh=BB07956476" target="">http://www.huachu.com.cn/itbook/itbookinfo.asp?lbbh=BB07956476</a><br />
<span style="font-size: 15px"><strong>Java 2核心技术 卷I：基础知识（原书第7版）和</strong></span><span style="font-size: 15px"><strong> Java 2 核心技术 卷II：高级特性（原书第7版）</strong></span><br />
我觉得这两本书可以好好读读，这两本书如同java的&#8220;新华字典&#8221;。不过刚刚接触java，没必要开始就从这两本书入手，因为太厚了，学习的兴趣可能会因此慢慢消失。不过，以后哪怕熟练掌握了Java，也应该好好读读这两本书。<br />
相关联接：<br />
<a class="" title="" href="http://www.dearbook.com.cn/book/104972" target="">http://www.dearbook.com.cn/book/104972</a><br />
<a class="" title="" href="http://www.dearbook.com.cn/book/104973" target="">http://www.dearbook.com.cn/book/104973</a><br />
<span style="font-size: 15px"><strong>Java编程思想：第3版</strong></span><br />
不知为什么，很多人都推荐新人看这本书。这本书应该是给有Java工作经验或者以前有C++工作经验的人看的。看名字就应该明白，这不是说基础的书籍，而是在基础上的思想的升华。有了上面的书籍，这本书买不买都无所谓了。如果没有Java基础来看这本书，将会是件非常痛苦的经历。另外，更有甚者，推荐新人看此书的英文版，让我觉得真不可思议。很多高手都从此书中收益不少，但并不是每个人都是高手。<br />
相关联接：<br />
<a class="" title="" href="http://www.dearbook.com.cn/book/29060" target="">http://www.dearbook.com.cn/book/29060</a><br />
<br />
<strong>Java面向对象编程<br />
</strong>孙卫琴的最新作品,是一本不错的基础书籍。<br />
<a href="http://www.dearbook.com.cn/book/110136"><font color="#0000ff">http://www.dearbook.com.cn/book/110136</font></a><br />
<br />
学好了Java，就可以进入J2EE的学习了，J2EE是个很庞大的概念，但最基本的就是为企业服务。刚开始接触J2EE，可能让人摸不着头脑，要学的知识太多了。其实，学习J2EE，可以从Web开发入手，边学边做，慢慢就领会了J2EE。Web开发，说窄点，就是做网站，说宽点，就是B/S开发。<br />
<br />
首先要学习的就是jsp和servlet，这两项技术是web开发的基础之基础。<br />
<strong>Servlet与JSP核心编程（第2版）<br />
</strong>我当时借阅了这本书，感觉在学servlet方面，这可以说得上是比较好的一本书了。<br />
<a href="http://www.dearbook.com.cn/book/22890"><font color="#0000ff">http://www.dearbook.com.cn/book/22890</font></a><br />
<br />
如果你对servlet有了一定了解，只是想学习一下jsp,你可以看看这本书：<br />
<strong>JSP程序设计<br />
</strong>尽管这是将一本英文原版拆成两本书来买，但我觉得这本书很适合jsp入门。<br />
<a href="http://www.dearbook.com.cn/book/91320"><font color="#0000ff">http://www.dearbook.com.cn/book/91320</font></a><br />
<br />
有了一定的jsp和servlet基础，就可以看一些流行的框架技术了。在这里将以目前流行的SSH为例。尽管ejb仍然有市场，但因为学习难度大和工作机会较少，所以初学者学习轻量级框架是进入J2EE的最佳捷径。<br />
<br />
首先需要介绍的是Struts,Struts尽管有一定岁月了，但至今它仍是开发人员首选的技术之一。目前还有一些与Struts相似的技术，如Tapestry ,JSF等，可以在学会Struts后再去学习，这样可以事半功倍。<br />
<br />
<strong>精通Struts：基于MVC的Java Web设计与开发<br />
</strong>这本书不用多说了，尽管人们对他的评价有褒有贬，但在我看来这本书可以说得上是孙大姐写得最好的一本书，入门，深入都可以在这本书得到。<br />
<a href="http://www.dearbook.com.cn/book/23040"><font color="#0000ff">http://www.dearbook.com.cn/book/23040</font></a><br />
<br />
另外，如果你不喜欢这本书，那就购买这本书吧：<br />
<strong>实战STRUTS<br />
</strong>有人说孙大姐的书就是抄袭了这本书，不管怎么说，都证明了这是一本好书。<br />
<a href="http://www.dearbook.com.cn/book/29882"><font color="#0000ff">http://www.dearbook.com.cn/book/29882</font></a><br />
<br />
Hibernate是SSH中的H，是一项ORM技术。<br />
<br />
<strong>Hibernate Quickly中文版</strong><br />
我当初学习hibernate时还没有这本书的中文版，我当时是看着英文版学会了hibernate，在我看来，这本书很适合对hibernate的入门。<br />
<a href="http://www.dearbook.com.cn/book/110547"><font color="#0000ff">http://www.dearbook.com.cn/book/110547</font></a><br />
<br />
关于hibernate深入的书籍，我认为最好的是hibernate in action。但他没有中文版。不过市面上有几本书都不错，可以自己挑选一本看：《精通Hibernate :Java对象持久化技术详解》、《深入浅出Hibernate》、《Hibernate开发及整合应用大全（珍藏版）》<br />
<br />
ORM技术另外还有一个Ibatis,在许多大项目中都可以看到Ibatis的踪影，这是因为Ibatis的仍然是面向SQL的，对SQL的操作有得天独厚的优势。它的学习难度也不大，只要看它的官方文档就足够了。现在《Ibatis in Action》英文版已经出版了。<br />
<br />
spring是现在流行的SSH框架中最重要也最难理解的一项技术。<br />
我当初理解spring是看它自带的例子理解的，因为当时市面上并没有什么好的入门书籍。<br />
不过现在有本书倒是值得推荐：<br />
<strong>spring 2.0技术手册<br />
</strong>这本书我在书店看过，觉得确实是本很好的入门书籍，因为spring的理解确实不是那么好理解，从示例出发能更好的理解spring的魅力。<br />
<a href="http://www.dearbook.com.cn/book/175891" target="_blank">http://www.dearbook.com.cn/book/175891</a><br />
<br />
spring的提升书籍我推荐：<br />
<strong>Spring框架高级编程<br />
</strong>这本书是spring的作者参与写的书，里面对技术的描述很到位，只是这本书的中文版的翻译有点生硬，但还过得去，最可惜的是这本书的纸张太差。只能看不能写。<br />
<a href="http://www.dearbook.com.cn/book/105486"><font color="#0000ff">http://www.dearbook.com.cn/book/105486</font></a><br />
</p>
<p><span style="font-weight: bold">Spring专业开发指南（Pro Spring中文版） <br />
</span></p>
<p>这也是一本很好的Spring书籍，虽然没有Spring框架高级编程那么全面，但翻译质量却胜于前者。</p>
<p><a href="http://www.dearbook.com.cn/book/108340" target="_blank">http://www.dearbook.com.cn/book/108340 <br />
</a></p>
<p>今年Struts2.0的推出，看来Struts1.x会慢慢淡出大家的视线了。</p>
<p>Struts2.0其实就是WebWork2.2，在现在没有Struts2.0书籍时候，</p>
<p><span style="font-weight: bold">WebWork in Action中文版 </span>值得大家阅读<span style="font-weight: bold">。</span></p>
<p><a href="http://www.dearbook.com.cn/book/123018" target="_blank">http://www.dearbook.com.cn/book/123018 </a><br />
<br />
能很好的看完上面书籍，并掌握60%，你就可以成为一名程序员了。呵呵。<br />
<br />
其实做好一名程序员，要求掌握的技术远不止这些，javascript和css都是必备的技术，只是大家似乎认为这只是美工的玩意，都不是很在乎，Ajax的出现，大大改变了大家对这两项技术的看法。<br />
Javascript没有什么好书，唯一一本《Javascript权威指南》还是一本字典工具书，CSS也有一本权威指南，但现在已经绝版了，要学好这两项技术，还是多从网上找例子看，或虚心请教美工。<br />
<br />
大家在应用Ajax技术时感到的难度，其实也是因为Javascript的问题，要理解Ajax很简单，网上搜索一下，很多小例子都能很好的理解Ajax。<br />
<br />
我买Ajax的书可以算多了，买了三本，《Ajax基础教程》，《征服Ajax--Web 2.0开发技术详解》，《征服Ajax+Lucene--构建搜索引擎》。<br />
《Ajax基础教程》是市面上第一本Ajax中文书籍，当时买回来也没怎么看，直到买了《征服Ajax+Lucene--构建搜索引擎》，我才体会了到什么是Ajax，可以是因为它的登陆例子简单实用吧。尽管不少人认为这本书是个大杂烩，但我却觉得买这本书很值，因为它，我开始使用Ajax，也开始使用Lucene引擎了。可能每个人的看书习惯不同，我更喜欢简单易懂的入门书籍，在我看来，只要入了门，就等于成功了一半。<br />
<br />
除了上面这些技术，还有不少技术需要掌握才能真正的做到开发时得心应手：</p>
<p><span style="font-weight: bold">Lucene IN ACTION 中文版</span> <br />
</p>
<p>一本讲述Lucene的权威书籍。<br />
</p>
<p><a href="http://www.dearbook.com.cn/book/124684" target="_blank">http://www.dearbook.com.cn/book/124684 <br />
</a></p>
<br />
<p>在掌握的这些技术的时候，也不要忘记理论的学习，这样才能更好的理解这些技术、框架。</p>
<p><span style="font-weight: bold">Java与模式 <br />
</span></p>
<p>这本书就不需要过多的介绍了。<br />
</p>
<p><a href="http://www.dearbook.com.cn/book/7401" target="_blank">http://www.dearbook.com.cn/book/7401 <br />
</a></p>
<p>先写到这里，以后再修改。</p>
<img src ="http://www.blogjava.net/rickhunter/aggbug/45346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2006-05-10 09:35 <a href="http://www.blogjava.net/rickhunter/articles/45346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转贴]用jdom技术将数据库数据写入读出xml文件</title><link>http://www.blogjava.net/rickhunter/articles/28114.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Sun, 15 Jan 2006 10:33:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/28114.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/28114.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/28114.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/28114.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/28114.html</trackback:ping><description><![CDATA[用jdom技术将数据库数据写入读出xml文件<br>

              <br>

//很多时候，为了避免多次访问/查询数据库重的数据或者便于察看，将需要的数据一次取出并写入xml文件 <br>

<br>

//通过查询条件m_condition 按照xmlMapPath的模式/模板 将从库中的数据写到resultXml <br>

//并返回记录条数 <br>

<br>

public int writeXML(String m_condtion,String xmlMapPath,String resultXml){ <br>

int recordNum=0; <br>

String tableName = "table"; <br>

String tableCol = "*"; <br>

String sql = "select " + tableCol + " from " + tableName + " where " + m_condtion; <br>

<br>

Document mapDoc = null; <br>

Document dataDoc = null; <br>

Document newDoc = null; <br>

//开始准备工作 <br>

try { <br>

DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); <br>

//Create the DocumentBuilder <br>

DocumentBuilder docbuilder = dbfactory.newDocumentBuilder(); <br>

//Parse the file to create the Document <br>

mapDoc = docbuilder.parse(xmlMapPath); <br>

<br>

dataDoc = docbuilder.newDocument(); <br>

//Instantiate the new Document <br>

newDoc = docbuilder.newDocument(); <br>

} catch (Exception e) { <br>

System.out.println(e.getMassege()); <br>

} <br>

<br>

//开始读取映射作用的template文件 <br>

<br>

Element mapRoot = mapDoc.getDocumentElement(); <br>

Node dataNode = mapRoot.getElementsByTagName("data").item(0); <br>

Element dataElement = (Element)dataNode; <br>

<br>

//Create a new element called "data" <br>

Element dataRoot = dataDoc.createElement("data"); <br>

<br>

try { <br>

/******** 这里创建一个连接conn,并创建statement <br>

根据不同的数据源创建 <br>

********************************/ <br>

ResultSet resultset = stmt.query(sql); <br>

//Get the ResultSet information <br>

ResultSetMetaData resultmetadata = resultset.getMetaData(); <br>

int numCols = resultmetadata.getColumnCount(); <br>

Log.write("db_to_xml:numCols:" + numCols); <br>

<br>

<br>

while (resultset.next()) { <br>

//Create a new element called "row" <br>

Element rowEl = dataDoc.createElement("row"); <br>

<br>

//为了便于浏览和读，创建列数,以id为标记 <br>

String colName = "id"; <br>

String colVal =Integer.toString(++recordNum); <br>

Element dataEl = dataDoc.createElement(colName); <br>

dataEl.appendChild(dataDoc.createTextNode(colVal)); <br>

<br>

rowEl.appendChild(dataEl); <br>

for (int i=1; i &lt;= numCols; i++) { <br>

<br>

colName = resultmetadata.getColumnName(i); <br>

//Get the column value <br>

colVal = resultset.getString(i); <br>

<br>

//Determine if the last column accessed was null <br>

if (resultset.wasNull()) { <br>

colVal = ""; <br>

} <br>

<br>

dataEl = dataDoc.createElement(colName); <br>

<br>

dataEl.appendChild(dataDoc.createTextNode(colVal)); <br>

<br>

rowEl.appendChild(dataEl); <br>

} <br>

//Add the row to the root element <br>

dataRoot.appendChild(rowEl); <br>

} <br>

} catch (Exception e) { <br>

Log.write(e.getMessage()); <br>

} finally { <br>

Log.write(" db_to_xml: Closing connections..."); <br>

<br>

} <br>

<br>

//Add the root element to the document <br>

dataDoc.appendChild(dataRoot); <br>

<br>

<br>

Node node1= mapRoot.getElementsByTagName("root").item(0); <br>

Element newRootInfo =(Element)node1; <br>

Log.write("After got newRootInfo ..."); <br>

//Retrieve the root and row information <br>

<br>

<br>

String newRootName = newRootInfo.getAttribute("name"); <br>

<br>

String newRowName= newRootInfo.getAttribute("rowName"); <br>

<br>

NodeList newNodesMap = mapRoot.getElementsByTagName("element"); <br>

<br>

//Create the final root element with the name from the mapping file <br>

Element newRootElement=null; <br>

<br>

newRootElement = newDoc.createElement(newRootName); <br>

<br>

<br>

NodeList oldRows = dataRoot.getElementsByTagName("row"); <br>

for (int i=0; i &lt; oldRows.getLength(); i++){ <br>

<br>

//Retrieve each row in turn <br>

Element thisRow = (Element)oldRows.item(i); <br>

<br>

//Create the new row <br>

Element newRow = newDoc.createElement(newRowName); <br>

<br>

for (int j=0; j &lt; newNodesMap.getLength(); j++) { <br>

<br>

//For each node in the new mapping, retrieve the information <br>

//First the new information... <br>

Element thisElement = (Element)newNodesMap.item(j); <br>

String newElementName = thisElement.getAttribute("name"); <br>

<br>

//Then the old information <br>

Element oldElement = (Element)thisElement.getElementsByTagName("content").item(0); <br>

String oldField = oldElement.getFirstChild().getNodeValue(); <br>

<br>

<br>

//Get the original values based on the mapping information <br>

Element oldValueElement = (Element)thisRow.getElementsByTagName(oldField).item(0); <br>

String oldValue = oldValueElement.getFirstChild().getNodeValue(); <br>

<br>

<br>

Element newElement = newDoc.createElement(newElementName); <br>

newElement.appendChild(newDoc.createTextNode(oldValue)); <br>

<br>

<br>

NodeList newAttributes = thisElement.getElementsByTagName("attribute"); <br>

for (int k=0; k &lt; newAttributes.getLength(); k++) { <br>

//Get the mapping information <br>

Element thisAttribute = (Element)newAttributes.item(k); <br>

String oldAttributeField = thisAttribute.getFirstChild().getNodeValue(); <br>

String newAttributeName = thisAttribute.getAttribute("name"); <br>

<br>

oldValueElement = (Element)thisRow.getElementsByTagName(oldAttributeField).item(0); <br>

String oldAttributeValue = oldValueElement.getFirstChild().getNodeValue(); <br>

<br>

<br>

newElement.setAttribute(newAttributeName, oldAttributeValue); <br>

} <br>

<br>

//Add the new element to the new row <br>

newRow.appendChild(newElement); <br>

} <br>

//Add the new row to the root <br>

newRootElement.appendChild(newRow); <br>

} <br>

//Add the new root to the document <br>

newDoc.appendChild(newRootElement); <br>

<br>

<br>

//把生成的xml文档（newDoc）写到文件中(路径名为resultXml) <br>

try{ <br>

TransformerFactory tFactory = TransformerFactory.newInstance(); <br>

Transformer transformer = tFactory.newTransformer(); <br>

Properties properties = transformer.getOutputProperties(); <br>

properties.setProperty(OutputKeys.ENCODING, "GB2312");//ISO8859_1，GB2312,UTF-8 <br>

properties.setProperty(OutputKeys.METHOD, "xml"); <br>

properties.setProperty(OutputKeys.VERSION, "1.0"); <br>

properties.setProperty(OutputKeys.INDENT, "yes"); <br>

transformer.setOutputProperties(properties); <br>

<br>

DOMSource source = new DOMSource(newDoc); <br>

<br>

StreamResult result = new StreamResult(new java.io.File(resultXml)); <br>

<br>

transformer.transform(source, result); <br>

//生成XML文件 完成 <br>

} catch (Exception e) { <br>

System.out.println("XML file write:"+e.getMessage()); <br>

} <br>

return recordNum; <br>

}<img src ="http://www.blogjava.net/rickhunter/aggbug/28114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2006-01-15 18:33 <a href="http://www.blogjava.net/rickhunter/articles/28114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>面试题</title><link>http://www.blogjava.net/rickhunter/articles/26849.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Fri, 06 Jan 2006 03:02:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/26849.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/26849.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/26849.html#Feedback</comments><slash:comments>7</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/26849.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/26849.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: JSP方面1、forward&nbsp;和redirect的区别答：forward是服务器请求资源，服务器直接访问目标地址的URL，把那个URL的响应内容读取过来，然后把这些内容再发给浏览器，浏览器根本不知道服务器发送的内容是从哪儿来的，所以它的地址栏中还是原来的地址。&nbsp;&nbsp;&nbsp;&nbsp;redirect就是服务端根据逻辑,发送一个状态码,告诉浏览器重新去请求那个地址，...&nbsp;&nbsp;<a href='http://www.blogjava.net/rickhunter/articles/26849.html'>阅读全文</a><img src ="http://www.blogjava.net/rickhunter/aggbug/26849.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2006-01-06 11:02 <a href="http://www.blogjava.net/rickhunter/articles/26849.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>多线程实现对多个客户端的监听.</title><link>http://www.blogjava.net/rickhunter/articles/15135.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Mon, 10 Oct 2005 06:04:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/15135.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/15135.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/15135.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/15135.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/15135.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 这是一个比较简单的例子来说明socket编程，服务器端使用了多线程来监听客户端。<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; 服务器端的代码：<br>
&nbsp;&nbsp;&nbsp; package SocketTest;<br>
<br>
&nbsp;&nbsp;&nbsp; import java.io.*;<br>
&nbsp;&nbsp;&nbsp; import java.net.*;<br>
&nbsp;&nbsp;&nbsp; import java.util.*;<br>
<br>
&nbsp;&nbsp;&nbsp; class SocketServer{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public SocketServer(){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Socket incoming;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ServerSocket so;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; so= new ServerSocket(8001);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("等待客户端连接。");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while(true){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; incoming =
so.accept( );<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("已连接客户端。");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GetInfo gi=new
GetInfo(incoming);//调用线程 <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch (IOException e){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp; e.printStackTrace();<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; }catch (IOException e){<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; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public static void main(String[] args){ <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; new SocketServer();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private static class GetInfo implements Runnable{&nbsp;&nbsp; //线程类<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private Socket incoming;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private String s=null;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; private BufferedReader b;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Thread t;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public GetInfo(Socket incoming){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; try{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.incoming=incoming;<br>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; b=new BufferedReader(new
InputStreamReader(incoming.getInputStream()));<br>
&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; t=new Thread(this);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; t.start();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }catch(IOException e){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; e.printStackTrace();<br>
&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; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public void run(){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (true){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s=b.readLine();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(s);<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if(s.equals("end")){<br>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; break;<br>
&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; }&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }catch(IOException e){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; 客户端的代码：<br>
&nbsp;&nbsp;&nbsp; package SocketTest;<br>
<br>
&nbsp;&nbsp;&nbsp; import java.io.*;<br>
&nbsp;&nbsp;&nbsp; import java.net.*;<br>
&nbsp;&nbsp;&nbsp; import java.util.*;<br>
<br>
&nbsp;&nbsp;&nbsp; public class SocketClient{<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public static void main(String[] args){<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; try{<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; Socket so = new Socket("localhost", 8001);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; System.out.println("连接服务器。");<br>
&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; BufferedReader b=new BufferedReader(new
InputStreamReader(System.in));<br>
&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; OutputStream outStream = so.getOutputStream();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter out = new PrintWriter(outStream);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; String s=null;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; while (true){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; s=b.readLine();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out.println("Client:"+s);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out.flush();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if(s.equals("end")){<br>
&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; &nbsp; break;<br>
&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;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }catch (IOException e){<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp; }<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
<br>
<br>
<br>
<img src ="http://www.blogjava.net/rickhunter/aggbug/15135.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2005-10-10 14:04 <a href="http://www.blogjava.net/rickhunter/articles/15135.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简单的四则计算器</title><link>http://www.blogjava.net/rickhunter/articles/13543.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Tue, 20 Sep 2005 09:31:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/13543.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/13543.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/13543.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/13543.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/13543.html</trackback:ping><description><![CDATA[效果图:<br>
<img src="http://www.blogjava.net/images/blogjava_net/rickhunter/Snap1.jpg" alt="Snap1.jpg" border="0" height="250" width="300"><br>
<br>
import java.awt.*;<br>
import java.awt.event.*;<br>
import javax.swing.*;<br>
import javax.swing.event.*;<br>
<br>
//定义了一个面板存放控件<br>
class MyPanel extends JPanel implements ActionListener<br>
{<br>
&nbsp;&nbsp; &nbsp;//定义了19个按钮（有两个还没实现），一个文本框<br>
&nbsp;&nbsp; &nbsp;JButton jb1=new JButton("1");<br>
&nbsp;&nbsp; &nbsp;JButton jb2=new JButton("2");<br>
&nbsp;&nbsp; &nbsp;JButton jb3=new JButton("3");<br>
&nbsp;&nbsp; &nbsp;JButton jb4=new JButton("4");<br>
&nbsp;&nbsp; &nbsp;JButton jb5=new JButton("5");<br>
&nbsp;&nbsp; &nbsp;JButton jb6=new JButton("6");<br>
&nbsp;&nbsp; &nbsp;JButton jb7=new JButton("7");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb8=new JButton("8");<br>
&nbsp;&nbsp; &nbsp;JButton jb9=new JButton("9");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb10=new JButton("0");<br>
&nbsp;&nbsp; &nbsp;JButton jb11=new JButton("+");<br>
&nbsp;&nbsp; &nbsp;JButton jb12=new JButton("-");<br>
&nbsp;&nbsp; &nbsp;JButton jb13=new JButton("*");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb14=new JButton("/");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb15=new JButton("+/-");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb16=new JButton("清零");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb17=new JButton("");&nbsp;&nbsp; &nbsp;//留着给以后加按钮<br>
&nbsp;&nbsp; &nbsp;JButton jb18=new JButton(".");//起符号作用的按钮，还没实现&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JButton jb19=new JButton("=");&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;JTextField jtf=new JTextField(20);<br>
&nbsp;&nbsp; &nbsp;String type;//定义了一个字符串存放算术运算符<br>
&nbsp;&nbsp; &nbsp;double a=0D,b=0D;//定义两个数字（算术运算符两边的数字）<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;public MyPanel()<br>
&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setHorizontalAlignment(JTextField.RIGHT);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;setLayout(null);//定义面板布局为空型<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb1.setBounds(new Rectangle(125, 148, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb2.setBounds(new Rectangle(70, 148, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb3.setBounds(new Rectangle(15, 148, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb4.setBounds(new Rectangle(125, 115, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb5.setBounds(new Rectangle(70, 115, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb6.setBounds(new Rectangle(15, 115, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb7.setBounds(new Rectangle(125, 80, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb8.setBounds(new Rectangle(70, 80, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb9.setBounds(new Rectangle(15, 80, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb10.setBounds(new Rectangle(15, 180, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb11.setBounds(new Rectangle(185, 148, 60, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb12.setBounds(new Rectangle(185, 180, 60, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb13.setBounds(new Rectangle(185, 115, 60, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb14.setBounds(new Rectangle(185, 80, 60, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb15.setBounds(new Rectangle(185, 45, 60, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb16.setBounds(new Rectangle(15, 45, 70, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb17.setBounds(new Rectangle(96, 45, 70, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb18.setBounds(new Rectangle(70, 180, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb19.setBounds(new Rectangle(125, 180, 45, 25));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setBounds(new Rectangle(15, 9, 231, 28));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jtf);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb1.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb2.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb3.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb4.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb5.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb6.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb7.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb8.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb9.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb10.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb11.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb12.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb13.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb14.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb15.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb16.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb17.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb18.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jb19.addActionListener(this);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb1);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb2);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb3);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb4);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb5);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb6);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb7);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb8);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb9);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb10);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb11);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb12);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb13);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb14);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb15);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb16);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb17);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb18);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;add(jb19);<br>
&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;public void actionPerformed(ActionEvent e)<br>
&nbsp;&nbsp; &nbsp;{&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(e.getSource()==jb1)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("1");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("1");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'1');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb2)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("2");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("2");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'2');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb3)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("3");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("3");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'3');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb4)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("4");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("4");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'4');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb5)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("5");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("5");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'5');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb6)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("6");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("6");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'6');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb7)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("7");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("7");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'7');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb8)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("8");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("8");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'8');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb9)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("9");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("9");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'9');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb10)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="equal")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'0');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb18)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().indexOf(".")&lt;1)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText()+'.');<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else <br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb18)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb16)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb11)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="add";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb12)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="subtract";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb13)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="multiply";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb14)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(jtf.getText().equals("0"))<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("0");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="divide";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;a=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText("");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(e.getSource()==jb19)<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(type=="add")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(Double.toString(a+b));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="equal";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(type=="subtract")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(Double.toString(a-b));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="equal";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(type=="multiply")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(Double.toString(a*b));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="equal";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;else if(type=="divide")<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;b=Double.parseDouble(jtf.getText());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;jtf.setText(Double.toString(a/b));<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;type="equal";<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;}<br>
}<br>
<br>
class Calculator extends JFrame<br>
{<br>
&nbsp;&nbsp; &nbsp;public Calculator()<br>
&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this.setTitle("计算器");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this.getContentPane().add(new MyPanel());<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;setSize(300,250);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;setVisible(true);<br>
&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;public static void main(String args[])<br>
&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;new Calculator();<br>
&nbsp;&nbsp; &nbsp;}<br>
}<img src ="http://www.blogjava.net/rickhunter/aggbug/13543.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2005-09-20 17:31 <a href="http://www.blogjava.net/rickhunter/articles/13543.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>如何在TreeSet中添加两个不具可比性的对象！</title><link>http://www.blogjava.net/rickhunter/articles/13541.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Tue, 20 Sep 2005 09:29:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/13541.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/13541.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/13541.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/13541.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/13541.html</trackback:ping><description><![CDATA[
		import java.util.TreeSet;<br>
<br>
class treeset{<br>
&nbsp;&nbsp; &nbsp;public static void main(String[] args){<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;TreeSet ts=new TreeSet();<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stud s1=new stud("张三");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;stud s2=new stud("李四");<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ts.add(s1);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;ts.add(s2);<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println(ts);<br>
&nbsp;&nbsp; &nbsp;}<br>
}<br>
<br>
class stud implements Comparable{<br>
&nbsp;&nbsp; &nbsp; private String name;<br>
&nbsp;&nbsp; &nbsp; <br>
&nbsp;&nbsp; &nbsp; public stud(String name){<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;this.name=name;<br>
&nbsp;&nbsp; &nbsp; }<br>
&nbsp;&nbsp; &nbsp; <br>
&nbsp;&nbsp; &nbsp; public int compareTo(Object o){<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;stud s=(stud)o;<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;int i=name.compareTo(s.name);<br>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp;return i;<br>
&nbsp;&nbsp; &nbsp; }<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp; &nbsp;public String toString(){<br>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return name;<br>
&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp; &nbsp;<br>
}<img src ="http://www.blogjava.net/rickhunter/aggbug/13541.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2005-09-20 17:29 <a href="http://www.blogjava.net/rickhunter/articles/13541.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用递归方法列出目录，在命令行中指定目录。</title><link>http://www.blogjava.net/rickhunter/articles/13539.html</link><dc:creator>千山鸟飞绝</dc:creator><author>千山鸟飞绝</author><pubDate>Tue, 20 Sep 2005 09:28:00 GMT</pubDate><guid>http://www.blogjava.net/rickhunter/articles/13539.html</guid><wfw:comment>http://www.blogjava.net/rickhunter/comments/13539.html</wfw:comment><comments>http://www.blogjava.net/rickhunter/articles/13539.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rickhunter/comments/commentRss/13539.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rickhunter/services/trackbacks/13539.html</trackback:ping><description><![CDATA[
		import java.io.*;<br>
<br>
&nbsp;class home3<br>
&nbsp;{<br>
&nbsp;&nbsp; public static void main(String[] args)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 判断是否提供了命令行参数。没有就用默认的。<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.length == 0) args = new String[] { "C:/Flexlm" };<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File f = new File(args[0]);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String[] s = f.list();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // 迭代所有目录里面的文件。<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; s.length; i++)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File fl = new File(f.getPath(), s[i]);<br>
<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; if (fl.isDirectory())<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;
System.out.println(fl.getCanonicalPath());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; main(new String [] { fl.getPath() });<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch(IOException e)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;}<img src ="http://www.blogjava.net/rickhunter/aggbug/13539.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rickhunter/" target="_blank">千山鸟飞绝</a> 2005-09-20 17:28 <a href="http://www.blogjava.net/rickhunter/articles/13539.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>