设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9667|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
5 I2 u! h% j9 `% Hsel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
  i+ ], x3 j2 f3 p6 M9 U/ E1 q
( G3 z5 Y% O, u7 |似乎缺少了一个SwarmUtils的类,不知道怎么回事
: v  s9 v. x3 t6 x3 k1 K  v, R$ r0 }! H8 S2 W$ K! \' j
朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;
( n' q3 l5 `5 _: x. I1 [
4 x8 n2 M& a) x3 Cpublic class SwarmUtils {
5 W8 H# q( x. i/ b  public static Selector getSelector(String name, String method) {/ J! y9 ^  A5 h6 L- S( Z5 Q
    Selector sel;
) H" T8 w( u- O, ]) }8 ?& c    try {, c7 y( ^4 n$ ?0 B) K3 S! Z) [- n
      sel = new Selector(Class.forName(name), method, false);' F& [) n" E% t& @
    } catch (Exception e) {7 U8 n. P' `4 s$ T! w
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");
  I2 n$ r; J0 X# u" l      System.err.println(name + "." + method + " returns " + e.getMessage());
/ V2 Z. v) k6 P- c      System.err.println("The process will be terminated.");
0 h3 h! J) S/ a* O      System.exit(1);9 x+ w  {; U8 M# e2 `+ c8 e8 k
      return null;
5 K1 R' ~7 J8 ?' }8 T    }) X2 c. m3 X- f6 S8 q0 U* ~
    return sel;
& f) Z0 j8 [2 ?( \  }6 M4 E7 x8 @9 L3 b5 Y

5 a5 ]7 m5 q6 M9 m  public static Selector getSelector(Object obj, String method) {
6 A  ]! _) G# {    Selector sel;
: g3 a9 i! g+ t' }% z    try {( \! Q5 H. ?) |. W
      sel = new Selector(obj.getClass(), method, false);
+ F$ ~9 w/ I/ q, E9 n    } catch (Exception e) {
# j: m& m6 M$ A+ C% y2 Q, v      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
9 k5 m5 T* n& |' k; C. ?          + (obj.getClass()).getName() + ".");
) _3 `5 A7 H9 h& [0 ?1 k& a! s9 x      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());: s6 q; `9 d. [" Y2 k
      System.err.println("The process will be terminated.");
$ }: S: r6 b' m$ A. W" z0 |+ N      System.exit(1);8 |1 T8 k7 e4 t2 K1 l4 y2 x
      return null;) n6 \8 {( C. k
    }% i' V5 X& q- M6 X
    return sel;
+ m4 \7 h$ w3 k- p& T$ h: M; O  }
( V- Z9 u7 y/ j+ f8 u/ A' G}

评分

参与人数 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-5-21 03:21 , Processed in 0.016029 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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