设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7938|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行
+ _5 A) S) v7 B+ s$ T5 I5 {sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
$ o3 Q, A/ d" G8 J' _+ y: r& V( ]) u6 r1 {0 c/ j" Y
似乎缺少了一个SwarmUtils的类,不知道怎么回事 6 K2 v( o, ?) b

' B; v2 V0 j/ L, e9 a朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;) j! {5 D2 C# X7 K

4 ^7 P2 n0 t# P; B3 Wpublic class SwarmUtils {
" T; D' Y# }, x. w  public static Selector getSelector(String name, String method) {) B0 ?* e1 V8 K1 [
    Selector sel;$ M, _# j- u* f  n
    try {& V6 o  p* c9 G( I" V+ b
      sel = new Selector(Class.forName(name), method, false);
7 n) P  y2 O" U0 c    } catch (Exception e) {# p% h2 z- b8 m7 ]
      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");1 ?9 G! ^# f( g  ?. T' N; Y
      System.err.println(name + "." + method + " returns " + e.getMessage());
# v! u; J. ]# r* j+ [      System.err.println("The process will be terminated.");/ p) z4 k) O3 y1 m
      System.exit(1);
& g4 Q- u0 ?/ i      return null;
# r1 w* ^& L  [7 J' Z$ h    }
& K& Z$ {: k9 _% P" s8 G* r    return sel;7 L- |+ ~% A5 y# P6 w0 ^9 M- [5 ~7 V
  }
* U: n3 l/ `0 m+ h" U9 z2 p! Y% @: a: R. ]' W7 |
  public static Selector getSelector(Object obj, String method) {" t; h# U) B+ b7 e
    Selector sel;# k) J2 O: w! u& @4 Y
    try {7 h  M: ~& v4 ]# I  ~8 d% S
      sel = new Selector(obj.getClass(), method, false);! s5 @0 x. g" z* w0 l2 S: Y. v: ^
    } catch (Exception e) {
8 F2 p$ O$ |. B! q  r, U      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
7 F' ?& t! W; ~* e' G          + (obj.getClass()).getName() + ".");
' s: {3 m4 \/ P$ U$ D1 s      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 E$ _: _* M; {# ~+ R/ e+ M
      System.err.println("The process will be terminated.");
3 }( L& {) p7 \3 S0 t+ U      System.exit(1);+ U$ u& V9 i( y. A- u
      return null;4 G2 ?/ f8 z9 v& h! ^$ _# g
    }
7 ]1 V8 S  |9 i8 e; V    return sel;
& [( Y' P7 m# @( Q  }" N# N7 H4 G0 m! }- Y
}

评分

参与人数 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, 2025-8-24 05:49 , Processed in 0.018722 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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