设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8728|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
+ F- y+ u0 o* tsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
& t8 a  s; q3 H$ G  q* z+ D' |( Q6 E! }
似乎缺少了一个SwarmUtils的类,不知道怎么回事
2 h) Q+ u: O* E4 x2 K4 L. Q; X" Y' e: Q4 |
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;6 M" A; O% ]$ C; v' e2 |& q6 Q

1 O0 L9 I$ Y) C$ L* K6 n6 mpublic class SwarmUtils {# r- L- Y( q- G
  public static Selector getSelector(String name, String method) {6 u5 t, h4 n, x  c
    Selector sel;1 H9 |% z# E6 x8 d
    try {
1 R! Q( V4 r5 r3 ?5 T# m! E      sel = new Selector(Class.forName(name), method, false);& X% y* X8 a5 o& F. K( o2 ~7 M+ |9 |' P
    } catch (Exception e) {- w5 R9 r& S! d9 v9 k
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
" X+ q( a0 s  g      System.err.println(name + "." + method + " returns " + e.getMessage());2 C9 `$ j; ~8 |3 F+ h0 b$ c( g
      System.err.println("The process will be terminated.");
; W+ o+ x9 G2 O+ u6 p% _, m: }1 S      System.exit(1);! u5 [3 x" a' p5 g1 A: ?! L# O" @
      return null;( B1 a( E# C: b6 P; u1 W
    }: z( T1 \# L7 T/ Y4 T% J. _
    return sel;
) ~: p- z, u' j3 b& E  }1 g4 z" _% _- n* C3 @
* m0 t- M3 e6 z) `' R
  public static Selector getSelector(Object obj, String method) {3 t( D  w8 ^- e! W, B' d
    Selector sel;6 Q$ p) p6 y; Y; ]8 C
    try {# X: H7 d% ~: w4 _
      sel = new Selector(obj.getClass(), method, false);# ^6 ~" E  Q' Q; p* K
    } catch (Exception e) {2 L& w4 b/ o* Z" m; d. O
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
" M) U+ v* }3 `" S: n          + (obj.getClass()).getName() + ".");3 F& w/ U# g- V5 e4 R* }! h1 @
      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());
2 M6 ?( p7 r2 a7 A  j9 f! G      System.err.println("The process will be terminated.");' I  `6 C, t* A7 @6 C
      System.exit(1);. L' m, L$ i6 T" h1 n7 k
      return null;
4 v* F! `1 {+ Y! ]    }4 B9 `9 g( n# W- j4 G
    return sel;1 W: p* |/ C) e- {3 G' }. m
  }
" @% B0 Y$ [( Z# j* \+ b! q1 u& B}

评分

参与人数 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-1-19 13:21 , Processed in 0.023675 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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