设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9008|回复: 7

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

  [复制链接]
发表于 2008-4-28 16:42:48 | 显示全部楼层 |阅读模式
这个程序我在eclipse下运行6 _5 n& i) h0 `% |$ O
sel=SwarmUtils.getSelector(market,"calculate");类似的语句不能运行
0 z/ F' E* ^# T$ n8 S
% t$ {3 c* ?3 u0 V: I. \6 U, q: W- E似乎缺少了一个SwarmUtils的类,不知道怎么回事
5 D, V  M3 N% b9 r6 C/ B, V8 V+ X" [  B
' A: d4 l% f% I; C' w! @" I# N1 D朋友们给个反馈??

本帖子中包含更多资源

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

x

评分

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

查看全部评分

发表于 2008-5-6 00:00:30 | 显示全部楼层
import swarm.Selector;) f% b: r: ]1 ^. w4 t4 h. d8 \. j4 O

% i8 U" ?. I) i3 _+ l- Ypublic class SwarmUtils {2 j' @8 v, Y/ Z$ s
  public static Selector getSelector(String name, String method) {0 i. i* U) [5 z# {2 u
    Selector sel;
" M% N) L2 c) a$ T3 R    try {
5 F! p! ^) ]6 W1 l      sel = new Selector(Class.forName(name), method, false);+ u: @$ H: A/ C6 W! O
    } catch (Exception e) {
/ B: p4 J- t  ]      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class " + name + ".");- h2 D4 J7 |4 ?- k* h! K( G
      System.err.println(name + "." + method + " returns " + e.getMessage());
* a2 X  d8 H# g& i      System.err.println("The process will be terminated.");
, f5 v8 V) k2 O! Y- z; i! K' U8 y      System.exit(1);
3 u) _) f7 `5 t+ _* z( C8 ^: Z0 P9 n      return null;
+ Z' P5 e% @3 ]. y1 V% O    }, ^' v5 H6 g& }* h% x
    return sel;
# g5 k6 {9 d/ M: Y) J( G0 o  }
$ S( K8 E7 ~! x! x: Q
" i: e- H# t1 g) R  public static Selector getSelector(Object obj, String method) {6 J( \( f, V, q# z7 D
    Selector sel;+ Z1 v* V7 E6 O& t# o6 B
    try {
4 E8 e/ b1 w2 `: h' Y/ o& G9 e      sel = new Selector(obj.getClass(), method, false);
; m, T5 T9 [' C- U    } catch (Exception e) {
9 x5 r+ Y9 S' h6 b% C- F      System.err.println("There was an error in creating a Selector for method " + method + "\nin Class "
3 \" U2 e( P  J$ n2 J3 p: Y8 B6 a          + (obj.getClass()).getName() + ".");
8 W0 u$ d1 ^8 V      System.err.println((obj.getClass()).getName() + "." + method + " returns " + e.getMessage());5 N; E" A7 C% Z) O) O  z; \
      System.err.println("The process will be terminated.");
6 ^3 T- S& Z5 y* e; d& |2 t) e      System.exit(1);( x/ E9 o5 G6 e: B3 M* s* c
      return null;4 ~/ O. W5 _8 l) M- k- o  y, \
    }
5 h3 m* z5 r7 D6 r( y! S- h# }    return sel;
( U+ |$ E, v. O) s1 ], I7 c. \! S  }, X+ v( n3 A0 x: i% J# T0 |" t
}

评分

参与人数 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-2-26 05:01 , Processed in 0.017886 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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