﻿<?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-rebel-随笔分类-Java</title><link>http://www.blogjava.net/rebel/category/18084.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 08 Mar 2007 16:57:38 GMT</lastBuildDate><pubDate>Thu, 08 Mar 2007 16:57:38 GMT</pubDate><ttl>60</ttl><item><title>Using CSS with GWT</title><link>http://www.blogjava.net/rebel/archive/2007/01/10/92968.html</link><dc:creator>忆了又忆</dc:creator><author>忆了又忆</author><pubDate>Wed, 10 Jan 2007 09:08:00 GMT</pubDate><guid>http://www.blogjava.net/rebel/archive/2007/01/10/92968.html</guid><description><![CDATA[
		<p align="justify">This is an attempt to put together a comprehensive reference for using Cascading Style Sheets with the Google Web Toolkit. I’ve assembled this document by first starting with the official documentation and then reviewing the source code. Where the source disagreed with the documentation I’ve sided with the source. I then did a runtime analysis of the sample applications that ship with the SDK to verify the results.</p>
		<p align="justify">I feel there is a need for this because the documentation that comes with the SDK is rather unhelpful. The SDK says, basically, that widget styles are conventionally named [project]-[widget], e.g., <code>gwt-Button, and style names correspond to CSS class names, so in order to style your button you would include something like</code></p>
		<div align="justify">
				<pre>.gwt-Button { font-size: 150%; }
				</pre>
		</div>
		<p align="justify">in your stylesheet. And that’s all it says. Really.</p>
		<p align="justify">I believe this documentation to be inadequate for a number of reasons.</p>
		<ol>
				<li>
						<div align="justify">The style is almost never as simple as the button example. Many GWT widgets correspond to messy nested tables, divs, and spans so it can be hard to know what it is you’re actually styling and what options are available to you in that context. </div>
				</li>
				<li>
						<div align="justify">The naming rule is not applied consistently within the SDK. The <code>DialogBox class, for one, does not follow the rule. </code></div>
				</li>
				<li>
						<div align="justify">In some situations similarly named styles (<code>*-selected*) are used in different or even contradictory manners making it hard to generalize your experience from one widget to another. </code></div>
				</li>
				<li>
						<div align="justify">In many cases the documentation is incorrect; the documented style simply is not implemented. The <code>ListBox class should, according to both the general rule above and the specific class documentation, implement a style named <code>gwt-ListBox. Nope, not there. Grep the source directory if you don’t believe me. </code></code></div>
				</li>
		</ol>
		<p align="justify">If I’ve left out a class below, it’s probably because it doesn’t participate in styling in any way. (I hope.) If you’re trying to read this straight through instead of just jumping to an item of interest, more power to you. If you find yourself yawning you might want to skip around a bit.</p>
		<p align="justify">With that said…</p>
		<h2 align="justify">AbsolutePanel</h2>
		<p align="justify">Implemented as a <code>DIV and by default sets <code>overflow to <code>hidden. Contents are positioned absolutely according to given <code>x, <code>y values unless <code>x == -1 and <code>y == -1 in which case the widget is positioned statically.</code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div style="overflow: hidden;"&gt;&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">Button</h2>
		<p align="justify">Implemented as HTML <code>BUTTON. Default style name is <code>gwt-Button and is used. No default attributes. Can contain text or HTML.</code></code></p>
		<div align="justify">
				<pre>&lt;button class="gwt-Button" /&gt;
				</pre>
		</div>
		<h2 align="justify">CellPanel</h2>
		<p align="justify">Implemented as a <code>TABLE. No default styles. Can set <code>border and <code>cell-spacing attributes.</code></code></code></p>
		<div align="justify">
				<pre>&lt;table&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">CheckBox</h2>
		<p align="justify">Implemented as HTML <code>CHECKBOX. Default style name is <code>gwt-CheckBox and is used. Automatically generates unique id of the form <code>checkN where <code>N is an integer. Uses <code>checked, <code>defaultChecked, and <code>disabled attributes. No default styles.</code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;checkbox class="gwt-CheckBox" /&gt;
				</pre>
		</div>
		<h2 align="justify">DeckPanel</h2>
		<p align="justify">Implemented using a <code>DIV containing any number of children. The visibility of the individual children are controlled using the <code>display attribute. The <code>DeckPanel sets <code>display to <code>'none' or <code>'' as appropriate.</code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div style="width: 100%; height: 100%"&gt;&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">DialogBox</h2>
		<p align="justify">Default style names are <code>gwt-DialogBox and <code>Caption and are both used. Implemented as a <code>DIV and the caption is also a <code>DIV. (Technically, the caption is an <code>HTML, which is a <code>Label, which is implemented using a <code>DIV.)</code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div class="gwt-DialogBox"&gt;
  &lt;table cell-spacing="0" cell-padding="0"&gt;
    &lt;tbody&gt;
      &lt;tr&gt;<br />      &lt;td&gt;&lt;div class="Caption"&gt;caption&lt;/div&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;
          content
        &lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">DockPanel</h2>
		<p align="justify">Implemented using <code>TABLE. <code>cell-spacing and <code>cell-padding attributes both default to 0. Nesting of <code>TR and <code>TD elements can get quite complicated in order to achieve desired layout.</code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;table cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">FlexTable</h2>
		<p align="justify">Just a <code>TABLE, there’s nothing funky going on here.</code></p>
		<div align="justify">
				<pre>&lt;table&gt;
  &lt;tbody&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">FlowPanel</h2>
		<p align="justify">Implemented as a <code>DIV with <code>display set to <code>inline.</code></code></code></p>
		<div align="justify">
				<pre>&lt;div style="display: inline;"&gt;content&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">FocusPanel</h2>
		<p align="justify">A <code>DIV. <code>FocusPanel is only important in that it publishes a number of events (<code>FOCUSEVENTS, <code>KEYEVENTS, <code>ONCLICK, and <code>MOUSEEVENTS) and is very useful for containing widgets that don’t publish their own events. See <a href="http://blogs.nubgames.com/code/?p=9">Drag-and-Drop with the Google Web Toolkit</a>.</code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div&gt;
  content
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">FocusWidget</h2>
		<p align="justify">Can be anything because it is implemented using whatever element is passed to it in the constructor. Interesting because it generates <code>FOCUSEVENTS and <code>KEYEVENTS.</code></code></p>
		<h2 align="justify">Frame</h2>
		<p align="justify">Implemented as an <code>IFRAME. Documented style name of <code>gwt-Frame is <strong>not</strong> implemented.</code></code></p>
		<div align="justify">
				<pre>&lt;iframe&gt;
&lt;/iframe&gt;
				</pre>
		</div>
		<h2 align="justify">Grid</h2>
		<p align="justify">Is just a table.</p>
		<div align="justify">
				<pre>&lt;table&gt;
  &lt;tbody&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">HTML</h2>
		<p align="justify">Implemented as a <code>DIV with default style name of <code>gwt-HTML. Can also set attribute <code>white-space to <code>normal or <code>nowrap.</code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div class="gwt-HTML"&gt;html&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">HTMLPanel</h2>
		<p align="justify">Is a <code>DIV that can either contain HTML exactly as <code>HTML<em>or</em> a collection of widgets. Does not use the <code>gwt-HTML style. The most useful attribute of an <code>HTMLPanel is that it contains the method <code>createUniqueId that returns an id of the form <code>HTMLPanel_N that can be used to apply styles to specific elements, as opposed to classes.</code></code></code></code></code></code></p>
		<p align="justify">Contrast this with <code>CheckBox which generates ids of the form <code>checkN without either the capitalization or the underscore. Not a bug, just another minor inconsistency.</code></code></p>
		<div align="justify">
				<pre>&lt;div&gt;
  content
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">HTMLTable</h2>
		<p align="justify">Unsurprisingly this class is implemented as a <code>TABLE. The most important things to know about <code>HTMLTable are (a) that it is the superclass for both <code>FlexTable and <code>Grid and (b) that it provides methods for setting the styles of individual rows or cells.</code></code></code></code></p>
		<p align="justify">It is also worth noting that <code>HTMLTable does not include a <code>THEAD. The 0th row therefore must be used as something of a pseudo-header by applying any necessary styles.</code></code></p>
		<div align="justify">
				<pre>&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;Row 0 -- if you want a header you have to fake it here.&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<div align="justify">
				<pre>// Style the first row to fake a header.
table.getRowFormatter(0).setStyleName("something-interesting");
				</pre>
		</div>
		<h2 align="justify">HorizontalPanel</h2>
		<p align="justify">Implemented using a <code>TABLE with all elements laid out as <code>TDs in a single <code>TR.</code></code></code></p>
		<div align="justify">
				<pre>&lt;table cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style="display: static; vertical-align: top;" align="left"&gt;Item 1&lt;/td&gt;
      &lt;td style="display: static; vertical-align: top;" align="left"&gt;Item 2&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">HyperLink</h2>
		<p align="justify">A <code>DIV containing an anchor. Documented style name <code>gwt-HyperLink is <strong>not</strong> implemented.</code></code></p>
		<div align="justify">
				<pre>&lt;div&gt;<a href="http://blogs.nubgames.com/code/?p=13#..."></a>&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">Image</h2>
		<p align="justify">Implemented as <code>IMG. Documented style of <code>gwt-Image is <strong>not</strong> implemented.</code></code></p>
		<div align="justify">
				<pre>&lt;img src="..." /&gt;
				</pre>
		</div>
		<h2 align="justify">Label</h2>
		<p align="justify">
				<code>Label is implemented as a <code>DIV with a default style name of <code>gwt-Label. <code>Labels do not interpret their content as HTML and by default allow word-wrap. If you want to use HTML content in your label then you should use an instance of <code>HTML. Both classes provide <code>MOUSEEVENTS.</code></code></code></code></code></code>
		</p>
		<p align="justify">You can change the default word-wrap by calling the <code>setWordWrap method.</code></p>
		<div align="justify">
				<pre>&lt;div class="gwt-Label"&gt;your text here&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">ListBox</h2>
		<p align="justify">Implemented using <code>SELECT with <code>OPTION for elements. Documented style name <code>gwt-ListBox is <strong>not</strong> implemented. Uses attributes <code>selected, <code>size, and <code>multiple as part of implementation.</code></code></code></code></code></code></p>
		<h2 align="justify">MenuBar</h2>
		<p align="justify">Implemented as a <code>DIV containing a <code>TABLE with menu items contained in <code>TD elements. A horizontal <code>MenuBar contains all menu items as children of a single <code>TR and a vertical <code>MenuBar uses a separate <code>TR for each item. Simple enough. The documented style name of <code>gwt-MenuBar is used and applied to the outer <code>DIV.</code></code></code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div class="gwt-MenuBar"&gt;
  &lt;table&gt;
    &lt;tbody&gt;
      <!-- example of a horizontal menu -->
      &lt;tr&gt;
        &lt;td class="gwt-MenuItem"&gt;text or html&lt;/td&gt;
        &lt;td class="gwt-MenuItem"&gt;text or html&lt;/td&gt;
      &lt;/tr&gt;
      &lt;!-- example of a vertical menu
        &lt;tr&gt;&lt;td class="gwt-MenuItem"&gt;text or html&lt;/td&gt;&lt;/tr&gt;
        &lt;tr&gt;&lt;td class="gwt-MenuItem"&gt;text or html&lt;/td&gt;&lt;/tr&gt;
      --&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">MenuItem</h2>
		<p align="justify">A <code>MenuItem is a <code>TD that can be inserted into a <code>MenuBar. The default style name is <code>gwt-MenuItem. A selected <code>MenuItem has the additional style name of <code>gwt-MenuItem-selected. I want to emphasize that the selected style is added to the default style, so that <code>class="gwt-MenuItem" becomes <code>class="gwt-MenuItem gwt-MenuItem-selected". This is <em>not</em> the case with all widgets and is another minor inconsistency in the GWT style design. See <code>StackPanel for an example of the opposite behavior.</code></code></code></code></code></code></code></code></code></p>
		<h2 align="justify">PasswordTextBox</h2>
		<p align="justify">Implemented as <code>PASSWORD. Uses <code>gwt-PasswordTextBox.</code></code></p>
		<h2 align="justify">PopupPanel</h2>
		<p align="justify">Just a <code>DIV.</code></p>
		<h2 align="justify">RadioButton</h2>
		<p align="justify">Implemented as an instance of <code>INPUT. Uses <code>gwt-RadioButton.</code></code></p>
		<h2 align="justify">RootPanel</h2>
		<p align="justify">A <code>RootPanel can be attached to any element, but it will discard all children previously belonging to that element. If you stop to think about it, this can be useful in contexts outside of your application init.</code></p>
		<h2 align="justify">ScrollPanel</h2>
		<p align="justify">A <code>DIV with <code>overflow set to <code>scroll or <code>auto. Defaults to <code>auto.</code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div style="overflow: auto;"&gt;
  content
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">SimplePanel</h2>
		<p align="justify">Just a <code>DIV.</code></p>
		<h2 align="justify">StackPanel</h2>
		<p align="justify">Implemented as a <code>TABLE with 2 rows per item. In each pair of rows the first contains the caption and the second contains the corresponding widget. By default the <code>TABLE is styled with <code>gwt-StackPanel. The <em>captions</em> are styled with <code>gwt-StackPanelItem and <code>gwt-StackPanelItem-selected. When an item is selected the caption’s unselected style <code>gwt-StackPanelItem is <em>replaced</em> with <code>gwt-StackPanelItem-selected. Not all widgets behave this way. See <code>MenuItem for an example of the opposite behavior.</code></code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;table class="gwt-StackPanel" cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
    <!-- two rows together constitute one item -->
    &lt;tr&gt;
      &lt;td class="gwt-StackPanelItem" height="1px"&gt;text/html&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td height="100%" valign="top"&gt;
        content -- a widget
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">TabBar</h2>
		<p align="justify">A <code>TabBar is implemented using a <code>HorizontalPanel so it is effectively a <code>TABLE. The style name <code>gwt-TabBar applies to the <code>TABLE — that is, to the actual tabs. The style <code>gwt-TabBarFirst applies to the first (effectively empty) HTML widget and is only useful for creating some sort of left border effect. The style <code>gwt-TabBarRest applies to that part of the <code>TabBar following the tabs.</code></code></code></code></code></code></code></code></p>
		<p align="justify">When a tab is selected the style <code>gwt-TabBarItem-selected gets <em>added</em> to the existing style. This behavior is like that of <code>MenuItem but opposite that of <code>StackPanel.</code></code></code></p>
		<div align="justify">
				<pre>&lt;table class="gwt-TabBar" cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td class="gwt-TabBarFirst" style="height: 100%;"&gt;&lt;div class="gwt-HTML" style="height: 100%;"&gt;&amp;amp;nbsp;&lt;/div&gt;&lt;/td&gt;
      &lt;td&gt;Tab #1&lt;/td&gt;
      &lt;td&gt;Tab #2&lt;/td&gt;
      &lt;td class="gwt-TabBarRest" style="width: 100%;"&gt;&lt;div class="gwt-HTML" style="height: 100%;"&gt;&amp;amp;nbsp;&lt;/div&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">TabPanel</h2>
		<p align="justify">Implemented as a <code>VerticalPanel containing a <code>TabBar and a <code>DeckPanel. In other words, it’s a bunch of nested tables. The style <code>gwt-TabPanel applies to the top-level <code>TABLE, <code>gwt-TabBar still applies to the contained <code>TABLE implementing the <code>TabBar, and <code>gwt-TabPanelBottom styles the <code>DIV containing the actual content.</code></code></code></code></code></code></code></code></code></code></p>
		<p align="justify">Note that the <code>TabBar gets the added default style of <code>width: 100%. This ensures that the <code>TabBar is as wide as the content panel and is the reason the <code>gwt-TabBarRest style is important. It’s all about how you want that empty space to look.</code></code></code></code></p>
		<div align="justify">
				<pre>&lt;table class="gwt-TabPanel" cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;
        <!-- this is the TabBar -->
        &lt;table class="gwt-TabBar" style="width: 100%;" cell-spacing="0" cell-padding="0"&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td class="gwt-TabBarFirst" style="height: 100%;"&gt;&lt;div class="gwt-HTML" style="height: 100%;"&gt;&amp;amp;nbsp;&lt;/div&gt;&lt;/td&gt;
	      <!-- tabs go here -->
              &lt;td class="gwt-TabBarRest" style="width: 100%;"&gt;&lt;div class="gwt-HTML" style="height: 100%;"&gt;&amp;amp;nbsp;&lt;/div&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;
        &lt;div class="gwt-TabPanelBottom"&gt;
	  <!-- content gets added here -->
	&lt;/div&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
		<h2 align="justify">TextArea</h2>
		<p align="justify">Implemented as a <code>TEXTAREA with a default style of <code>gwt-TextArea.</code></code></p>
		<h2 align="justify">TextBox</h2>
		<div align="justify">
				<pre>&lt;input type="text" class="gwt-TextBox" /&gt;
				</pre>
		</div>
		<h2 align="justify">Tree</h2>
		<p align="justify">Implemented as a <code>DIV containing nested <code>TreeItems. The style name <code>gwt-Tree applies to the <code>DIV and the style <code>overflow defaults to <code>auto.</code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div class="gwt-Tree" style="overflow: auto;"&gt;
  <!-- contains a hidden root node that is the true parent of all TreeItems -->
  &lt;div style="position: relative; margin-left: 16;" (handle)&gt;
    &lt;table&gt;
      &lt;tr&gt;
        &lt;td&gt;&lt;/td&gt;
        &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    <span><!-- visible TreeItems begin here --></span>
  &lt;/div&gt;
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">TreeItem</h2>
		<p align="justify">Implemented as a <code>TABLE nested within a <code>DIV. The styles <code>gwt-TreeItem and <code>gwt-TreeItem-selected apply to the nested content element, a <code>SPAN. The selected state <code>gwt-TreeItem-selected<em>replaces</em> the unselected state <code>gwt-TreeItem, like <code>StackPanel but unlike <code>MenuItem or <code>TabBar.</code></code></code></code></code></code></code></code></code></code></p>
		<div align="justify">
				<pre>&lt;div style="position: relative; margin-left: 16; white-space: nowrap" (handle)&gt;
  &lt;table style="white-space: nowrap;"&gt;
    &lt;tr&gt;
      &lt;td style="vertical-align: middle;"&gt;&lt;img src="tree_white.gif" /&gt;&lt;/td&gt;
      &lt;td style="vertical-align: middle;"&gt;<span class="gwt-TreeItem" style="DISPLAY: inline">content</span>&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  <span style="WHITE-SPACE: nowrap">children</span>
&lt;/div&gt;
				</pre>
		</div>
		<h2 align="justify">VerticalPanel</h2>
		<p align="justify">Implemented using a <code>TABLE with all elements laid out as <code>TRs.</code></code></p>
		<div align="justify">
				<pre>&lt;table cell-spacing="0" cell-padding="0"&gt;
  &lt;tbody&gt;
    &lt;tr&gt;&lt;td style="display: static; vertical-align: top;" align="left"&gt;Item 1&lt;/td&gt;&lt;/tr&gt;
    &lt;tr&gt;&lt;td style="display: static; vertical-align: top;" align="left"&gt;Item 2&lt;/td&gt;&lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;
				</pre>
		</div>
<img src ="http://www.blogjava.net/rebel/aggbug/92968.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rebel/" target="_blank">忆了又忆</a> 2007-01-10 17:08 <a href="http://www.blogjava.net/rebel/archive/2007/01/10/92968.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>扑克发牌算法</title><link>http://www.blogjava.net/rebel/archive/2006/12/05/85704.html</link><dc:creator>忆了又忆</dc:creator><author>忆了又忆</author><pubDate>Tue, 05 Dec 2006 14:36:00 GMT</pubDate><guid>http://www.blogjava.net/rebel/archive/2006/12/05/85704.html</guid><description><![CDATA[
		<p>扑克发牌算法是棋牌游戏中常用的基础算法，也是游戏开发人员需要熟悉的基础算法之一。下面介绍一下该算法的一种实现方式。 <br />首先给扑克牌中每张牌设定一个编号，下面算法实现的编号规则如下： <br />1.红桃按照从小到大依次为： 1-13 <br />2.方块按照从小到大依次为： 14-26 <br />3.黑桃按照从小到大依次为： 27-39 <br />4.梅花按照从小到大依次为： 40-52 <br />5.小王为 53 ，大王为 54 </p>
		<p>算法实现如下： <br />1.首先按照以上编号规则初始化一个包含 108 个数字的数组 <br />2.每次随机从该数组中抽取一个数字，分配给保存玩家数据的数组 </p>
		<p>实现该功能的代码如下所示： </p>
		<p>import java.util.*; </p>
		<p>/** <br /> * 发牌算法的实现 <br /> * 要求：把 2 副牌，也就是 108 张，发给 4 个人，留 6 张底牌 <br /> */ </p>
		<p>public class Exec {<br />    public static void main(String[] args) {<br />        // 存储 108 张牌的数组<br />        int[] total = new int[108];<br />        // 存储四个玩家的牌<br />        int[][] player = new int[4][25];<br />        // 存储当前剩余牌的数量<br />        int leftNum = 108;<br />        // 随机数字<br />        int ranNumber;<br />        // 随机对象<br />        Random random = new Random();<br />        // 初始化数组<br />        for (int i = 0; i &lt; total.length; i++) {<br />            total[i] = (i + 1) % 54;<br />            // 处理大小王编号<br />            if (total[i] == 0) {<br />                total[i] = 54;<br />            }<br />        }<br />        // 循环发牌<br />        for (int i = 0; i &lt; 25; i++) {<br />            // 为每个人发牌<br />            for (int j = 0; j &lt; player.length; j++) {<br />                // 生成随机下标<br />                ranNumber = random.nextInt(leftNum);<br />                // 发牌<br />                player[j][i] = total[ranNumber];<br />                // 移动已经发过的牌<br />                total[ranNumber] = total[leftNum - 1];<br />                // 可发牌的数量减少 1<br />                leftNum--;<br />            }<br />        }<br />        // 循环输出玩家手中的牌<br />        for (int i = 0; i &lt; player.length; i++) {<br />            for (int j = 0; j &lt; player[i].length; j++) {<br />                System.out.print("  " + player[i][j]);<br />            }<br />            System.out.println();<br />        }<br />        // 底牌<br />        for (int i = 0; i &lt; 8; i++) {<br />            System.out.print("  " + total[i]);<br />        }<br />        System.out.println();<br />    }<br />}</p>
<img src ="http://www.blogjava.net/rebel/aggbug/85704.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rebel/" target="_blank">忆了又忆</a> 2006-12-05 22:36 <a href="http://www.blogjava.net/rebel/archive/2006/12/05/85704.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>正则表达式笔记</title><link>http://www.blogjava.net/rebel/archive/2006/12/05/85700.html</link><dc:creator>忆了又忆</dc:creator><author>忆了又忆</author><pubDate>Tue, 05 Dec 2006 14:24:00 GMT</pubDate><guid>http://www.blogjava.net/rebel/archive/2006/12/05/85700.html</guid><description><![CDATA[
		<p>1.[] 与 ()的区别 </p>
		<p>[a-zA-Z0-9] 在包含的字符中 , 匹配其中一个 , 可匹配 ”!a!” </p>
		<p>(abc) 在包含的字符中 , 都要逐一匹配 , 而且有顺序 , 其实就是说 ,() 里面就是一个字正则式 , 可匹配 ”3abc93” </p>
		<p>2. 表达式之间千万不能有空格 </p>
		<p>3.构造检查 email的正则表达式 </p>
		<p>    /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/ </p>
		<p>在一个完整的 email 地址中有三个部分 : <br />　1. 用户名 ( 在 '@' 左边的一切 ), <br />　2.'@',<br />　3. 服务器名 ( 就是剩下那部分 ). <br />用户名可以含有大小写字母阿拉伯数字 , 句号 ('.'), 减号 ('-'), and 下划线 ('_'). 服务器名字也是符合这个规则 , 当然下划线除外 . </p>
		<p>现在 , 用户名的开始和结束都不能是句点 . 服务器也是这样 . 还有你不能有两个连续的句点他们之间至少存在一个字符，好现在我们来看一下怎么为用户名写一个匹配模式 : <br />     /^[\w-]+$/ </p>
		<p>现在还不能允许句号的存在 . 我们把它加上 : <br />　 /^[\w-]+(\.[\w-]+) * $/ <br />上面的意思就是说 : " 以至少一个规范字符（除了 . ）开头 , 后面跟着 0 个或者多个 以点开始的字符串 ." </p>
		<p>然后是后面一部分 , 在网上流传的一种做法是 , 后面的一部分是跟前面那部分一样的 , 但是我觉得有点不妥 , 难道 abc@abc 这样也符合一个 email 地址格式吗 ? 我试过不少的系统 , 都不允许这样输入的 , 必需要你输入如 abc@abc.abc 这样的格式才行．所以后面部分是略有不同的． </p>
		<p>   \^[\w-]+(\.[w-]+) ＋ $\ <br />上面的意思就是说 : " 以至少一个规范字符（除了 . ）开头 , 后面跟着 １个或者多个 以点开始的字符串 ." </p>
		<p>好 . 现在只需要用 ”@” 把两部分连接 : <br />　/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[w-]+)+$/</p>
		<p>这就是完整的 email 认证匹配模式了 , 在 JS 中只需要调用 <br />    reg = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[w-]+)+$/; <br />    reg.exec(input); </p>
		<p>返回为 true, 就是说 input 是一个 email 地址 . <br />通过这种方法就可以得到是否为 email 了 ! </p>
		<p> </p>
<img src ="http://www.blogjava.net/rebel/aggbug/85700.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rebel/" target="_blank">忆了又忆</a> 2006-12-05 22:24 <a href="http://www.blogjava.net/rebel/archive/2006/12/05/85700.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>