一个临时数组,其中包含了名为rs 的字串(rs 代表“结果集”——Result Set)。结果集要么直接从n 复
制(没有find 关键字),要么选择性地从包含了 find 关键字的n 中的字串复制。最后会检查strip
Checkbox,看看用户是不是希望将名字中多余的部分删除(默认为“是”)。若答案是肯定的,则用
StripQualifiers。strip()做这件事情;反之,就将列表简单地显示出来。
在 init()中,大家也许认为在设置布局时需要进行大量繁重的工作。事实上,组件的布置完全可能只需要极
少的工作。但象这样使用BorderLayout 的好处是它允许用户改变窗口的大小,并特别能使 TextArea (文本
区域)更大一些,这意味着我们可以改变大小,以便毋需滚动即可看到更长的名字。
编程时,大家会发现特别有必要让这个工具处于运行状态,因为在试图判断要调用什么方法的时候,它提供
了最好的方法之一。
17。3 复杂性理论
下面要介绍的程序的前身是由Larry O"Brien 原创的一些代码,并以由 Craig Reynolds 于 1986 年编制的
“Boids”程序为基础,当时是为了演示复杂性理论的一个特殊问题,名为“凸显”(Emergence)。
这儿要达到的目标是通过为每种动物都规定少许简单的规则,从而逼真地再现动物的群聚行为。每个动物都
能看到看到整个环境以及环境中的其他动物,但它只与一系列附近的“群聚伙伴”打交道。动物的移动基于
三个简单的引导行为:
(1) 分隔:避免本地群聚伙伴过于拥挤。
(2) 方向:遵从本地群聚伙伴的普遍方向。
(3) 聚合:朝本地群聚伙伴组的中心移动。
更复杂的模型甚至可以包括障碍物的因素,动物能预知和避免与障碍冲突的能力,所以它们能围绕环境中的
固定物体自由活动。除此以外,动物也可能有自己的特殊目标,这也许会造成群体按特定的路径前进。为简
化讨论,避免障碍以及目标搜寻的因素并未包括到这里建立的模型中。
尽管计算机本身比较简陋,而且采用的规则也相当简单,但结果看起来是真实的。也就是说,相当逼真的行
为从这个简单的模型中“凸显”出来了。
程序以合成到一起的应用程序/程序片的形式提供:
//: FieldOBeasts。java
// Demonstration of plexity theory; simulates
// herding behavior in animals。 Adapted from
// a program by Larry O"Brien lobrien@msn。
import java。awt。*;
import java。awt。event。*;
import java。applet。*;
import java。util。*;
class Beast {
643
…………………………………………………………Page 645……………………………………………………………
int
x; y; // Screen position
currentSpeed; // Pixels per second
float currentDirection; // Radians
Color color; // Fill color
FieldOBeasts field; // Where the Beast roams
static final int GSIZE = 10; // Graphic size
public Beast(FieldOBeasts f; int x; int y;
float cD; int cS; Color c) {
field = f;
this。x = x;
this。y = y;
currentDirection = cD;
currentSpeed = cS;
color = c;
}
public void step() {
// You move based on those within your sight:
Vector seen = field。beastListInSector(this);
// If you"re not out in front
if(seen。size() 》 0) {
// Gather data on those you see
int totalSpeed = 0;
float totalBearing = 0。0f ;
float distanceToNearest = 100000。0f;
Beast nearestBeast =
(Beast)seen。elementAt(0);
Enumeration e = seen。elements();
while(e。hasMoreElements()) {
Beast aBeast = (Beast) e。nextElement();
totalSpeed += aBeast。currentSpeed;
float bearing =
aBeast。bearingFromPointAlongAxis(
x; y; currentDirection);
totalBearing += bearing;
float distanceToBeast =
aBeast。distanceFromPoint(x; y);
if(distanceToBeast 《 distanceToNearest) {
nearestBeast = aBeast;
distanceToNearest = distanceToBeast;
}
}
// Rule 1: Match average speed of those
// in the list:
currentSpeed = totalSpeed / seen。size();
// Rule 2: Move towards the perceived
// center of gravity of the herd:
currentDirection =
totalBearing / seen。size();
// Rule 3: Maintain a minimum distance
// from those around you:
644
…………………………………………………………Page 646……………………………………………………………
if(distanceToNearest field。maxSpeed) {
currentSpeed = field。maxSpeed;
}
}
}
else { // You are in front; so slow down
currentSpeed =
(int)(currentSpeed * field。decayRate);
}
// Make the beast move:
x += (int)(Math。cos(currentDirection)
* currentSpeed);
y += (int)(Math。sin(currentDirection)
* currentSpeed);
x %= field。xExtent;
y %= field。yExtent;
if(x 《 0)
x += field。xExtent;
if(y 《 0)
y += field。yExtent;
}
public float bearingFromPointAlongAxis (
int originX; int originY; float axis) {
// Returns bearing angle of the current Beast
// in the world coordiante system
try {
double bearingInRadians =
Math。atan(
(this。y originY) /
(this。x originX));
// Inverse tan has two solutions; so you
// have to correct for other quarters:
if(x 《 originX) {
if(y 《 originY) {
bearingInRadians += (float)Math。PI;
}
else {
bearingInRadians =
(float)Math。PI bearingInRadians;
}
}
// Just subtract the axis (in radians):
return (float) (axis bearingInRadians);
} catch(ArithmeticException aE) {
// Divide by 0 error possible on this
if(x 》 originX) {
return 0;
小说推荐
- 软件工程实践者的思想(PDF格式)
- -Page 1-大 道 至 简—软件工程实践者的思想周爱民(Aimingoo 著-Page 2-序2004 年 11 月初爱民(Aimingoo)第一次把他的书稿给我,我翻看了一下,第一反应讲的是感想。这不错,在技
- 最新章:第26章
- 深入浅出MFC第2版(PDF格式)
- -Page 1-Page 2-山高月小山高月小 水落石出水落石出山高月小山高月小 水落石出水落石出-Page 3-深入淺出MFC(第版 使用Visual C 5.0 MFC 4.2)Dissecting MFC(Second Edition Using Visual C 5.0 MFC 4.2)侯俊
- 最新章:第309章
- VB2008从入门到精通(PDF格式英文版)
- -Page 1(R)The eXperT’s Voice inBeginningVB 2008From Novice to ProfessionalChristian Gross-Page 2-Page 3-Beginning VB 2008From Novice to Professional■C
- 最新章:第214章
- C语言游戏编程从入门到精通(PDF格式)
- -Page 1-Page 2-Page 3-Page 4-Page 5-Page 6-Page 7-Page 8-Page 9-Page 10-Page 11-Page 12-Page 13-Page 14
- 最新章:第4章
- JMS简明教程(PDF格式)
- -Page 1-JMS1.1规范中文版卫建军2007‐11‐22-Page 2
- 最新章:第28章
- C语言实例教程(PDF格式)
- -Page 1-前 言Visual C+是开发运行于Windows 95和Windows NT环境下的Win32应用程序的可视化编程工具中最重要的成员之一,它为软件开发人员提供了完整的编辑、编译和调试工具和建立于Win32 API(ApplicationProgramming Interface)基
- 最新章:第143章
- 神祗之眼 (正式版)第7卷(全文完)作者:百里芜虚
- 第五十一章离12月25日的圣诞节还有两天,纽约已经换上了节日的盛装,几天前的一场大雪令整个城市一片银白。人们笑逐颜开,都纷纷开始为节日做准备,商家为了在节日打开销路纷纷推出各种优惠促销手段,纽约的大街小巷全都这样热闹。依沙那被老婆打发出来买过节要用的杂货,而女儿则和凯妮一起到百货商场去买衣服去了。对
- 最新章:第23章
- SQL语言艺术(PDF格式)
- -Page 1-SQLSSQQLL语言艺术内容介绍本书分为12章,每一章包含许多原则或准则,并通过举例的方式对原则进行解释说明。这些例子大多来自于实际案例,对九种SQL经典查询场景以及其性能影响讨论,非常便于实践,为你数据库应用维护人员阅读。资深 SQL 专家 Stéphane Faroult倾力打
- 最新章:第27章
- php程序设计简明教程(DOC格式)
- -Page 1-PHP 程序设计简明教程PHP 讲义 第 1 页 共 90 页-Page 2-目录序 4第一章 PHP 简介 6
- 最新章:第31章