设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9103|回复: 7

[交流] 科学网于同奎先生的源程序

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
' ^/ L' K) d  J% \1 x/ q; usel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行; v) a) I0 r6 h

- Q: i6 l9 U  R- j) D& y似乎缺少了一个SwarmUtils的类,不知道怎么回事
5 z1 @1 }8 b# p5 L+ l
- K, c* J! q# v' H% l% L" p朋友们给个反馈??

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1仿真币 +12 +1 收起 理由
苘苘 + 12 + 1

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;# e, a% Q* K  v/ v
9 Y& W& U- `  @8 ]+ `) a* p
public class SwarmUtils {; p9 v+ p! E/ n. B2 V3 A3 R4 O+ G
  public static Selector getSelector(String name, String method) {6 R3 l7 f( n+ f. [+ k
    Selector sel;( @3 A+ m. |: L+ @0 @5 f) J4 n
    try {
3 a3 B, o6 w* w; H0 B! g      sel = new Selector(Class.forName(name), method, false);& l0 e9 }0 p' p0 P- ?0 H- e; `2 W
    } catch (Exception e) {/ z/ a# E' U+ c3 b3 T& l8 g
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- C! [8 Q- ^; S9 K% ], v
      System.err.println(name + "." + method + " returns " + e.getMessage());9 u" _0 @& H( n" X
      System.err.println("The process will be terminated.");
$ o9 x4 [: q& Y; e  b7 Y5 t      System.exit(1);
6 Y8 d% v3 p% d, z8 k9 e: _% l, f" Q      return null;
3 {6 |! [( [" Q0 d5 {    }
; U& K& R3 z6 Q0 R$ b    return sel;2 H2 ]& `' Q5 [+ Y! c4 u5 @
  }" a1 l5 r7 _' H0 a: f2 g, Q
+ T$ Q+ b4 G0 ~8 ]9 B
  public static Selector getSelector(Object obj, String method) {
0 f2 b3 ?9 a. N7 _' H0 j    Selector sel;
3 G' O" x# l. o, ]    try {; b5 d. r$ J' G$ G' `/ \6 N
      sel = new Selector(obj.getClass(), method, false);) I. M) P6 F# s
    } catch (Exception e) {
; u% e6 H. Y2 c( ^; E4 T: d5 t      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
6 R4 H! H4 Y3 W          + (obj.getClass()).getName() + ".");' Y' w6 S  Q( I: T+ L. d) {% }9 C
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());$ F% K7 ~: w$ F4 A2 a# W3 X* g
      System.err.println("The process will be terminated.");3 p. q( I7 w  m( x
      System.exit(1);
# O4 _% V7 @. M2 k8 B, ?: [) _      return null;1 W- Z9 G5 T! d" u) r7 w
    }! S2 y( T1 }' ?4 C+ q! H) Z' C0 `
    return sel;& p, G, b; z1 m( G, u) V
  }
) Q; @- J6 C. h& Q7 r4 N& x! \  F( R}

评分

参与人数 1仿真币 +21 +1 收起 理由
苘苘 + 21 + 1 我很赞同

查看全部评分

发表于 2008-11-20 19:49:58 | 显示全部楼层
very good.
发表于 2008-11-28 11:12:43 | 显示全部楼层
这个……在SimpleBug的代码中自带了一个SwarmUtils的类……答案如2楼所示……
发表于 2009-3-12 14:52:51 | 显示全部楼层

谢谢

学习学习
发表于 2009-12-2 20:20:58 | 显示全部楼层
请问一下代码是添加在哪里的啊?
发表于 2012-5-22 10:31:21 | 显示全部楼层
是单独建立一个新的JAVA文件,文件名为SwarmUtils.java,然后把上述代码复制进去就可以了
发表于 2013-1-25 12:27:29 | 显示全部楼层
学习。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-3-14 23:48 , Processed in 0.014995 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表